这代码什么意思啊

yuzhihuade 2013-12-14 08:25:52
package adasdasdad;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class MyFrame1 extends JFrame implements ActionListener {
public JLabel label1, label2, label3;
public JButton btn1, btn2;
public JTextField userName, userPassword;
static ResourceBundle rs;
static{
//Locale.setDefault(new Locale("en","US"));
rs=ResourceBundle.getBundle("fkjava", Locale.getDefault());
}

public MyFrame1() {
super(rs.getString("title"));
this.setSize(180, 300);
//this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.getContentPane().setBackground(Color.GREEN);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
}

private void init() {
Container panel = this.getContentPane();
panel.setLayout(new FlowLayout());
label1 = new JLabel(rs.getString("label1"));
panel.add(label1);
userName = new JTextField(10);
panel.add(userName);
label2 = new JLabel(rs.getString("label2"));
panel.add(label2);

userPassword = new JPasswordField(10);
panel.add(userPassword);
btn1 = new JButton(rs.getString("btn1"));
btn1.setActionCommand("btn1");
btn1.addActionListener(this);
btn1.setEnabled(false);
panel.add(btn1);
btn2 = new JButton(rs.getString("btn2"));
btn2.setActionCommand("btn2");
btn2.addActionListener(this);
panel.add(btn2);
label3=new JLabel(rs.getString("wellcom"));
panel.add(label3);
userName.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
if (!userName.getText().equals("")) {
btn1.setEnabled(true);
} else {
btn1.setEnabled(false);
}
}
});

}

public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case "btn1":
String name=userName.getText();
String password=userPassword.getText();
if("admin".equals(name)&&"123".equals(password)){
String msg=MessageFormat.format(rs.getString("msg"),
name+"---"+password,new Date());
label3.setText(msg);
}else{
label3.setText(rs.getString("error"));

}
break;
case "btn2":
userName.setText("");
userPassword.setText("");
btn1.setEnabled(false);
break;
}

}

public static void main(String[] args) {
new MyFrame1();

}

}
...全文
1379 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengyuankai272 2014-02-04
  • 打赏
  • 举报
回复
用swing的一个登陆界面
1183035829qq 2014-02-04
  • 打赏
  • 举报
回复
我是菜鸟,看不懂啊······
Seven丨 2014-02-04
  • 打赏
  • 举报
回复
自己运行一遍,目测是用Java做窗口程序。。登陆用。。
teemai 2014-01-31
  • 打赏
  • 举报
回复
就一个swing的登录界面
另一花生 2014-01-30
  • 打赏
  • 举报
回复
public static void main(String[] args) { new MyFrame1(); } 先是调用MyFrame() ,应该是弹出一个窗口,然后初始化你的参数
WayneXuan 2013-12-14
  • 打赏
  • 举报
回复
国际化,使支持多种语言

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧