五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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)容,獲取打印下拉框【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
石狮市| 治县。| 莱阳市| 慈溪市| 乐都县| 体育| 江都市| 融水| 汤原县| 阳春市| 高平市| 卢龙县| 洪洞县| 定远县| 沂南县| 翁源县| 项城市| 泰兴市| 祁门县| 扶余县| 柳林县| 勃利县| 新余市| 来安县| 醴陵市| 吉林市| 佛坪县| 凤翔县| 雷波县| 平邑县| 剑河县| 河池市| 苏尼特左旗| 五指山市| 双牌县| 安溪县| 长垣县| 常州市| 安平县| 伊宁县| 汝南县|