目标:1.点击数字,在文本框中显示;(完成)2.点击START按钮,触发倒计时(再写个倒计时的类),同时BUTTON上出现图片;3.当时间为零时,图片变样;代码:import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; public class MyFrame extends JFrame { private JButton buttons[];public MyFrame(){super("Microwave");Container container=getContentPane();container.setLayout(new BorderLayout());JButton b=new JButton("START");JButton b1=new JButton("PUT YOUR FOOD!");JTextField field=new JTextField(20);container.add(b,BorderLayout.NORTH);Panel center=new Panel();Panel p=new Panel();center.setLayout(new BorderLayout());p.setLayout(new GridLayout(3,3));buttons = new JButton[9];buttons[0]=new JButton("7");buttons[1]=new JButton("8");buttons[2]=new JButton("9");buttons[3]=new JButton("4");buttons[4]=new JButton("5");buttons[5]=new JButton("6");buttons[6]=new JButton("1");buttons[7]=new JButton("2");buttons[8]=new JButton("3");for(int i=0;i<9;i++){p.add(buttons[i]); }for(int i=0;i<buttons.length;i++){buttons[i].addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {field.setText(e.getActionCommand());}});}center.add(field, BorderLayout.NORTH);center.add(p, BorderLayout.CENTER);container.add(b1,BorderLayout.CENTER);container.add(center, BorderLayout.EAST);setVisible(true);setSize(450,300);}}}import javax.swing.*;import java.awt.*; public class Microwave { public static void main(String[] args) { MyFrame ceshi =new MyFrame();ceshi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } 困难:主要实现第二个功能,如何通过点击START按钮来将文本框中的数字倒计时啊???望大神指教,十分感谢!!!
添加回答
举报
0/150
提交
取消