level 9
GrubbyT
楼主
package rest; import java.awt.event.WindowAdapter ;
import java.awt.event.ActionListener ;
import java.awt.event.WindowEvent ;
import java.awt.event.ActionEvent ;
import java.awt.Color ;
import java.awt.Font ;
import javax.swing.JFrame ;
import javax.swing.JButton ;
import javax.swing.JLabel ;
import javax.swing.JTextField ;
import javax.swing.JPanel ; class ActionHandle extends test{
private JFrame frame = new JFrame("姓名大作战") ;
private JButton submit = new JButton("确定");
private JButton reset = new JButton("重置");
private JLabel name1Lab = new JLabel("name1:") ;
private JLabel name2Lab = new JLabel("name2:") ;
private JLabel infoLab = new JLabel("请输入姓名") ;
private JTextField name1Text = new JTextField(10) ;
private JTextField name2Text = new JTextField() ;
public ActionHandle(){
Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,12) ;
infoLab.setFont(fnt) ; // 设置标签的显示文字
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==submit){
String tname1 = name1Text.getText() ;
String tname2 = name2Text.getText() ;
X = tname1;
Y = tname2;
System.out.println(X);
System.out.println(Y);
}
}
}) ;
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==reset){
name1Text.setText("") ;
name2Text.setText("") ;
infoLab.setText("请输入姓名") ;
}
}
}) ;
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(1) ;
}
}) ; // 加入事件
frame.setLayout(null) ;
name1Lab.setBounds(5,5,60,20) ;
name2Lab.setBounds(5,30,60,20) ;
infoLab.setBounds(5,65,220,30) ;
name1Text.setBounds(65,5,100,20) ;
name2Text.setBounds(65,30,100,20) ;
submit.setBounds(165,5,60,20) ;
reset.setBounds(165,30,60,20) ;
frame.add(name1Lab) ;
frame.add(name2Lab) ;
frame.add(infoLab) ;
frame.add(name1Text) ;
frame.add(name2Text) ;
frame.add(submit) ;
frame.add(reset) ;
frame.setSize(280,130) ;
frame.setBackground(Color.WHITE) ;
frame.setLocation(300,200) ;
frame.setVisible(true) ; }
}; public class test{
static String X = null;
static String Y = null;
public static void main(String args[]){
new ActionHandle() ;
System.out.println(X);
System.out.println(Y);
System.out.println("----");
//System.out.println(actionPerformed(1));
}
};
2011年12月29日 15点12分
1
import java.awt.event.ActionListener ;
import java.awt.event.WindowEvent ;
import java.awt.event.ActionEvent ;
import java.awt.Color ;
import java.awt.Font ;
import javax.swing.JFrame ;
import javax.swing.JButton ;
import javax.swing.JLabel ;
import javax.swing.JTextField ;
import javax.swing.JPanel ; class ActionHandle extends test{
private JFrame frame = new JFrame("姓名大作战") ;
private JButton submit = new JButton("确定");
private JButton reset = new JButton("重置");
private JLabel name1Lab = new JLabel("name1:") ;
private JLabel name2Lab = new JLabel("name2:") ;
private JLabel infoLab = new JLabel("请输入姓名") ;
private JTextField name1Text = new JTextField(10) ;
private JTextField name2Text = new JTextField() ;
public ActionHandle(){
Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,12) ;
infoLab.setFont(fnt) ; // 设置标签的显示文字
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==submit){
String tname1 = name1Text.getText() ;
String tname2 = name2Text.getText() ;
X = tname1;
Y = tname2;
System.out.println(X);
System.out.println(Y);
}
}
}) ;
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==reset){
name1Text.setText("") ;
name2Text.setText("") ;
infoLab.setText("请输入姓名") ;
}
}
}) ;
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(1) ;
}
}) ; // 加入事件
frame.setLayout(null) ;
name1Lab.setBounds(5,5,60,20) ;
name2Lab.setBounds(5,30,60,20) ;
infoLab.setBounds(5,65,220,30) ;
name1Text.setBounds(65,5,100,20) ;
name2Text.setBounds(65,30,100,20) ;
submit.setBounds(165,5,60,20) ;
reset.setBounds(165,30,60,20) ;
frame.add(name1Lab) ;
frame.add(name2Lab) ;
frame.add(infoLab) ;
frame.add(name1Text) ;
frame.add(name2Text) ;
frame.add(submit) ;
frame.add(reset) ;
frame.setSize(280,130) ;
frame.setBackground(Color.WHITE) ;
frame.setLocation(300,200) ;
frame.setVisible(true) ; }
}; public class test{
static String X = null;
static String Y = null;
public static void main(String args[]){
new ActionHandle() ;
System.out.println(X);
System.out.println(Y);
System.out.println("----");
//System.out.println(actionPerformed(1));
}
};