最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java swing超詳細(xì)翻譯 變色 焦點獲取事件,判斷輸入內(nèi)容,獲取打印下拉框【詩書畫唱】

2020-05-28 13:11 作者:詩書畫唱  | 我要投稿

要做的功能是點擊按鈕的時候判斷用戶輸入的內(nèi)容是否大于6位并且小于12位,如果符合就打印符合內(nèi)容

否則打印不符合內(nèi)容


package swing;


public class mains {


public static void main(String[] args) {


new swingBianSe();

}


}


package swing;

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;


import javax.swing.*;

public class swingBianSe extends JFrame{

public static JLabel lb1,lb2,lb3=null;

public static JCheckBox ck1,ck2,ck3=null;

public static JRadioButton rb1,rb2=null;

public static JTextArea jt1=null;

public static JButton btn1=null;

public static JTextField txt=null;

public static JPasswordField pwd=null;

public static JComboBox com1=null;

//在構(gòu)造方法里寫內(nèi)容

public swingBianSe(){

//使用控件的三個步驟

lb1=new JLabel("請輸入你的用戶名");

lb2=new JLabel("請輸入你的用戶密碼");

lb1.setBounds(250,100,150,30);

lb2.setBounds(250,140,150,30);

this.add(lb1);

this.add(lb2);

com1=new JComboBox();

com1.addItem("管理員");

com1.addItem("普通用戶");

com1.addItemListener(new swingBianSe_shijian(this));

com1.setBounds(100,50,140,30);

this.add(com1);

pwd=new JPasswordField();

pwd.setBounds(100,140,150,30);

this.add(pwd);

//1.聲明控件

txt=new JTextField();

txt.addFocusListener(new swingBianSe_shijian(this));

//2.設(shè)置控件的位置

txt.setBounds(100,100,150,30);

//3.添加到窗體上

this.add(txt);

btn1=new JButton("提交");

btn1.setBounds(100,140,70,30);

btn1.addActionListener(new swingBianSe_shijian(this));

//實例化一個類的時候首先執(zhí)行的是構(gòu)造方法

this.add(btn1);

this.setTitle("詩書畫唱的窗體 ");

this.setLayout(null);

this.setSize(600,600);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

}

}


class swingBianSe_shijian implements ActionListener,

ItemListener,FocusListener{

//聲明一個空變量用來接收傳入的窗體

public swingBianSe ss;

public swingBianSe_shijian(swingBianSe s){

ss=s;

}

@Override

public void actionPerformed(ActionEvent arg0) {

//接收窗體的內(nèi)容



}

@Override

public void itemStateChanged(ItemEvent arg0) {

// TODO Auto-generated method stub

String str=ss.com1.getSelectedItem().toString();

JOptionPane.showMessageDialog(null,str);

}

@Override

public void focusGained(FocusEvent arg0) {

// TODO Auto-generated method stub


}

//失去焦點

@Override

public void focusLost(FocusEvent arg0) {

// TODO Auto-generated method stub

//獲取文本框中的內(nèi)容

String uname=ss.txt.getText();

if(uname.length()>6&&uname.length()<12){

ss.lb1.setText("用戶名輸入正確");

ss.lb1.setForeground(Color.green);

}else{

ss.lb1.setText("請輸入6到12位的用戶名");

ss.lb1.setForeground(Color.red);

}

}



}



Java swing超詳細(xì)翻譯 變色 焦點獲取事件,判斷輸入內(nèi)容,獲取打印下拉框【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
龙海市| 崇左市| 镇平县| 锡林郭勒盟| 丰原市| 武胜县| 青神县| 吉木乃县| 扎赉特旗| 图木舒克市| 富源县| 清徐县| 正安县| 武城县| 布尔津县| 扶沟县| 隆尧县| 聊城市| 遂宁市| 顺昌县| 松溪县| 盐池县| 双鸭山市| 陕西省| 奎屯市| 凤山市| 青阳县| 伽师县| 秀山| 曲松县| 新竹市| 白沙| 兴义市| 宁都县| 子长县| 金寨县| 灵山县| 江都市| 松滋市| 招远市| 凤山市|