当前位置: 代码迷 >> Java相关 >> 事件处理
  详细解决方案

事件处理

热度:250   发布时间:2006-07-07 22:15:39.0
事件处理
import java.awt.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
public class NianFen
{
public static void main(String args[])
{
NianFrame frame=new NianFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}
class NianFrame extends JFrame implements ActionListener
{
JTextField T1,T2;
JButton A;
JLabel a,b;
JPanel p;
public NianFrame()
{
setTitle("Nian Fen");
Container con=getContentPane();
con.setLayout(new BorderLayout());
a=new JLabel("input year:");
p=new JPanel();
p.setLayout(new GridLayout(5,1));
p.add(a);
T1=new JTextField(20);
p.add(T1);
b=new JLabel("result:");
p.add(b);
T2=new JTextField(20);
p.add(T2);
A=new JButton("Yes");
p.add(A);
con.add(p,BorderLayout.CENTER);
A.addActionListener(this);
setVisible(true);
setSize(200,200);
pack();
}
public void actionporformed(ActionEvent e)
{
double t;
try
{
t=Double.parseDouble(T1.getText());
}
catch ( NumberFormatException numberFormat )
{
JOptionPane.showMessageDialog( this,"Invalid Operand", "Invalid Number Format",
JOptionPane.ERROR_MESSAGE );
return;
}
if(e.getSource()==A)
{
if((t%400==0||(t%4==0&&t%100!=0)))
T2.setText("Yes");
else
T2.setText("No");
}
}
}
----------------解决方案--------------------------------------------------------
什么问题?
----------------解决方案--------------------------------------------------------
现在没问题了
哈哈!~~
----------------解决方案--------------------------------------------------------
public void actionporformed(ActionEvent e)
大小写错了
----------------解决方案--------------------------------------------------------
  相关解决方案