锘??xml version="1.0" encoding="utf-8" standalone="yes"?> public class TestQq { }
import javax.swing.*;
import java.awt.event.*;
public class MyQq extends JFrame implements ActionListener {
private ImageIcon logImg=null;
private JLabel welcomeJL=null;
private JLabel usenameJL=null;
private JLabel passwordJL=null;
private JTextField usenameJT=null;
private JPasswordField passwordJP=null;
private JButton loginJB=null;
private JButton closeJB=null;
private JPanel one=null;
private JPanel two=null;
private JPanel three=null;
private JPanel four=null;
public MyQq(String title){
super(title);
logImg=new ImageIcon("com/progrm/Qq/img/qq.gif") ;
welcomeJL=new JLabel(logImg);
usenameJL=new JLabel("甯愬彿");
usenameJT=new JTextField(10);
passwordJL=new JLabel("瀵嗙爜");
passwordJP=new JPasswordField(10);
loginJB=new JButton("鐧婚檰");
loginJB.addActionListener(this);
closeJB=new JButton("鍙栨秷");
closeJB.addActionListener(this);
one=new JPanel();
one.add(welcomeJL);
two=new JPanel();
two.add(usenameJL);
two.add(usenameJT);
three=new JPanel();
three.add(passwordJL);
three.add(passwordJP);
four=new JPanel();
four.add(loginJB);
four.add(closeJB);
this.setLayout(new GridLayout(4,1));
this.add(one);
this.add(two);
this.add(three);
this.add(four);
this.setSize(331,244);
this.setLocation(520, 310);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==loginJB){
if(usenameJT.getText().equals("wl") && passwordJP.getText().equals("123")){
JOptionPane.showMessageDialog(this,"鐧婚檰鎴愬姛");
}
else{
JOptionPane.showMessageDialog(this,"瀵嗙爜閿欒");
}
}
if(e.getSource()==closeJB){
System.exit(0);
}
}
}
public static void main(String[] args) {
new MyQq("QQ鐢ㄦ埛鐧婚檰");
}
]]>
//瀵煎叆鐩稿叧鐨勫寘
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Counter extends JFrame implements ActionListener,KeyListener,MouseListener{
//
//瀹氫箟鐩稿叧緇勪歡
private JTextField oneJT=null;
private JTextField twoJT=null;
private JTextField threeJT=null;
private JTextField fourJT=null;
private JTextField fiveJT=null;
private JTextField sixJT=null;
private JTextArea oneJTA=null;
private JButton oneJB=null;
private JButton twoJB=null;
private JButton threeJB=null;
private JButton fourJB=null;
private JPanel oneJPL=null;
private JPanel twoJPL=null;
private JPanel threeJPL=null;
private JPanel fourJPL=null;
private JPanel fiveJPL=null;
private JPanel sixJPL=null;
private JPanel sevenJPL=null;
//鍒涘緩紿椾綋鐨勬瀯閫犳柟娉?br />
public Counter(String title){
super(title);
//
//娣誨姞鐩稿叧緇勪歡
oneJT=new JTextField(6); //瀛樻斁絎竴涓繍綆楁暟鐨勬枃鏈
twoJT=new JTextField(6); //瀛樻斁絎簩涓繍綆楁暟鐨勬枃鏈
oneJPL=new JPanel();
oneJPL.add(oneJT);
oneJPL.add(twoJT);
threeJT=new JTextField(6); //瀛樻斁 + 榪愮畻緇撴灉鐨勬枃鏈
threeJT.setEditable(false);
oneJB=new JButton("+"); //鏄劇ず + 鍙風殑鎸夐挳
oneJB.addActionListener(this); //緇欐寜閽坊鍔犲姩浣滅洃鍚?br />
twoJPL=new JPanel();
twoJPL.add(threeJT);
twoJPL.add(oneJB);
fourJT=new JTextField(6); //瀛樻斁-榪愮畻緇撴灉鐨勬枃鏈
fourJT.setEditable(false);
twoJB=new JButton("-"); //鏄劇ず - 鐨勬寜閽?br />
twoJB.addActionListener(this); //緇欐寜閽坊鍔犲姩浣滅洃鍚?br />
threeJPL=new JPanel();
threeJPL.add(fourJT);
threeJPL.add(twoJB);
fiveJT=new JTextField(6);
fiveJT.setEditable(false);
threeJB=new JButton("*"); //鏄劇ず * 鐨勬寜閽?br />
threeJB.addActionListener(this); //緇欐寜閽坊鍔犲姩浣滅洃鍚?br />
fourJPL=new JPanel();
fourJPL.add(fiveJT);
fourJPL.add(threeJB);
sixJT=new JTextField(6);
sixJT.setEditable(false);
fourJB=new JButton("/"); //鏄劇ず / 鐨勬寜閽?br />
fourJB.addActionListener(this); //緇欐寜閽坊鍔犲姩浣滅洃鍚?br />
fiveJPL=new JPanel();
fiveJPL.add(sixJT);
fiveJPL.add(fourJB);
sixJPL=new JPanel(new GridLayout(4,1));
sixJPL.add(twoJPL);
sixJPL.add(threeJPL);
sixJPL.add(fourJPL);
sixJPL.add(fiveJPL);
oneJTA=new JTextArea("璇存槑:鍒嗗埆鍚戝墠闈㈢殑涓や釜杈撳叆妗嗕腑杈撳叆絎竴涓?絎簩涓猏n 榪愮畻鏁?鐐瑰嚮涓嶅悓鐨勬寜閽細榪涜鐩稿搴旂殑榪愮畻,\n 騫舵妸緇撴灉鏄劇ず鍦ㄦ寜閽墠闈㈢殑緇撴灉妗嗕腑" );
oneJTA.setColumns(5);
oneJTA.setRows(5);
oneJTA.setEditable(false); //璁劇疆鏂囨湰鍩熷唴瀹逛笉鍙敼鍙?br />
sevenJPL=new JPanel(new GridLayout(1,0));
sevenJPL.add(oneJTA);
this.add(oneJPL);
this.add(sixJPL);
this.add(sevenJPL);
//
//璁劇疆紿椾綋
this.setBounds(280,380,350,290); //璁劇疆紿椾綋鐨勫ぇ灝忓拰寮瑰嚭浣嶇疆
//this.setLayout(new GridLayout(3,0)); //璁劇疆紿椾綋鐨勫竷灞妯″紡
this.setLayout(new FlowLayout());
this.setDefaultCloseOperation(EXIT_ON_CLOSE); //璁劇疆鍏抽棴紿椾綋鐨勫悓鏃墮噴鏀懼唴瀛?br />
this.setResizable(false); //璁劇疆紿椾綋澶у皬涓嶅彲璋冩暣
this.setVisible(true); //璁劇疆紿椾綋涓哄彲瑙佺殑
}
//
//瀹炵幇鍔ㄤ綔鐩戝惉鐨勬柟娉?br />
public void actionPerformed(ActionEvent e){
if(e.getSource()==oneJB){ //褰撶獥浣撶洃嫻嬪埌 + 鎸夐挳琚偣鍑繪椂鎵ц榪欎釜if鐨勫瓙浠g爜
double jt=Integer.parseInt(oneJT.getText());
double jt1=Integer.parseInt(twoJT.getText());
threeJT.setText(jt+jt1+""); //鎶婅繍綆楃殑緇撴灉鏄劇ず鍦ㄧ粨鏋滄枃鏈涓?br />
}
if(e.getSource()==twoJB){ //褰撶獥浣撶洃嫻嬪埌 - 鎸夐挳琚偣鍑繪椂鎵ц榪欎釜if鐨勫瓙浠g爜
double jt=Integer.parseInt(oneJT.getText());
double jt1=Integer.parseInt(twoJT.getText());
fourJT.setText(jt-jt1+""); //鎶婅繍綆楃殑緇撴灉鏄劇ず鍦ㄧ粨鏋滄枃鏈涓?br />
}
if(e.getSource()==threeJB) { //褰撶獥浣撶洃嫻嬪埌 * 鎸夐挳琚偣鍑繪椂鎵ц榪欎釜if鐨勫瓙浠g爜
double jt=Integer.parseInt(oneJT.getText());
double jt1=Integer.parseInt(twoJT.getText());
fiveJT.setText(jt*jt1+""); //鎶婅繍綆楃殑緇撴灉鏄劇ず鍦ㄧ粨鏋滄枃鏈涓?br />
}
if(e.getSource()==fourJB) { //褰撶獥浣撶洃嫻嬪埌 / 鎸夐挳琚偣鍑繪椂鎵ц榪欎釜if鐨勫瓙浠g爜
if(twoJT.getText().equals("0")) {
JOptionPane.showMessageDialog(this,"琚櫎鏁頒笉鑳戒負0");
}else {
double jt=Integer.parseInt(oneJT.getText());
double jt1=Integer.parseInt(twoJT.getText());
sixJT.setText(jt/jt1+""); //鎶婅繍綆楃殑緇撴灉鏄劇ず鍦ㄧ粨鏋滄枃鏈涓?br />
}
}
}
//
//瀹炵幇閿洏鐩戝惉鐨勬柟娉?br />
public void keyPressed(KeyEvent e){
}
public void keyReleased(KeyEvent e){
}
public void keyTyped(KeyEvent e){
}
//
//瀹炵幇榧犳爣鐩戝惉鐨勬柟娉?br />
public void mouseClicked(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
}
public class TsetCounter {
public static void main(String[] args) {
new Counter("璁$畻鍣?);
//new test("嫻嬭瘯");
}
}