import java.awt.*;
import java.awt.event.*;
public class QueryFrame extends Frame
{
private TextField text_char;
private Checkbox check_str;
int year;
int result=1;
public QueryFrame()
{
super("判断闰年");
this.setBounds(280,100,300,240);
this.setBackground(java.awt.Color.lightGray);
text_char=new TextField("2011",10);
this.add(text_char);
this.add(new Label("年份"));
check_str=new Checkbox("");
this.add(check_str);
if(year%400==0||year%4==0&&year%100!=0)
check_str(result);
}
public static void main(String args[])
{new QueryFrame();
}
}
它显示说我check_str(result);错了,
我就是编一个java程序
在一个文本框中输入一个整数,判断是否是闰年,是checkbox就处于选中状态的
------解决方案--------------------
用SWING重新给你做了一下界面,AWT太恶心了
- Java code
/** * Created by IntelliJ IDEA. * User: gaoyong * Date: 2011-10-14 * Time: 22:48:04 * To change this template use File | Settings | File Templates. */import javax.swing.*;import java.awt.*;import java.awt.event.*;public class QueryFrame extends JFrame{ private JTextField text_char; private JCheckBox check_str; private JButton button; int year; int result=1; public QueryFrame(){ super("判断闰年"); this.setBounds(280,100,300,240); this.setBackground(java.awt.Color.lightGray); text_char=new JTextField("2011",10); button=new JButton("提交"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String yearStr=text_char.getText(); year=Integer.parseInt(yearStr); if(year%400==0||year%4==0&&year%100!=0){// check_str.setState(result==1); check_str.setSelected(result==1); check_str.repaint(); } } }); this.getContentPane().setLayout(new FlowLayout()); this.getContentPane().add(text_char); this.getContentPane().add(new JLabel("年份")); this.getContentPane().add(button); check_str=new JCheckBox(""); this.getContentPane().add(check_str); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String args[]) { new QueryFrame(); }}