⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 microwaveoven.java

📁 小学期时候的作业
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

/**************************************************************
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_1\Project_Name.java
 *
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.
 */

import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.*;


// Represents time data and contains get and set methods.
 class CookingTime
{
   private int minute;
   private int second;
   public CookingTime(int min,int sec)
   {
   	  minute=min;
   	  second=sec;
   }  
   public void setMinute(int min)
   {
   	   minute=min;
   }
   public void setSecond(int sec)
   {
   	   second=sec;
   }
   public int getMinute()
   {
   	return minute;
   }
   public int getSecond()
   {
   	return second;
   }
   public boolean OK()            //烹调完毕
   {
   	  if (minute==0 && second==0)
   	    return true;
   	  else
   	    return false;
   }
   public void process()          //递减过程,在定时器每次激发时来改变分和秒
   {
   	  if(minute>=1)
   	    {
   	     if(0!=second)
   	       second=second-1;
   	     else
   	       {
   	       	minute=minute-1;
   	        second=59;
   	       }
   	    }
   	   else
   	     {
   	      if(0!=second)
   	       second=second-1;
   	     }       
   }
} // end class CookingTime




public class MicrowaveOven extends JFrame
{
   // JPanel for microwave window
   private JPanel windowJPanel;

   // JPanel for microwave controls
   private JPanel controlJPanel;

   // JTextField for cooking time
   private JTextField displayJTextField;

   // JButtons to set cooking time
   private JButton oneJButton;
   private JButton twoJButton;
   private JButton threeJButton;
   private JButton fourJButton;
   private JButton fiveJButton;
   private JButton sixJButton;
   private JButton sevenJButton;
   private JButton eightJButton;
   private JButton nineJButton;
   private JButton zeroJButton;

   // JButtons to start and clear timer
   private JButton startJButton;
   private JButton clearJButton;

   // Timer to count down seconds
   private Timer clockTimer;

   // String for storing digits entered by user
   private String timeToDisplay = "";
   
   private CookingTime MicrowaveTime = new CookingTime(0,0);

   // DecimalFormat to format time output
   private DecimalFormat timeFormat = new DecimalFormat( "00" );
   
   //全局变量
   //int i=0;        //控制Timer的激发次数
   int cooktime; //设置时间

   // no-argument constructor
   public MicrowaveOven() 
   {
      createUserInterface();
   }
   
   // create and position GUI components; register event handlers
   private void createUserInterface()
   {
      // get content pane for attaching GUI components
      Container contentPane = getContentPane();

      // enable explicit positioning of GUI components
      contentPane.setLayout( null );
      
      // set up windowJPanel
      windowJPanel = new JPanel();
      windowJPanel.setBounds( 16, 16, 328, 205 );
      windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
      contentPane.add( windowJPanel );
      
      // set up controlJPanel
      controlJPanel = new JPanel();
      controlJPanel.setBounds( 368, 16, 149, 205 );
      controlJPanel.setBorder( new LineBorder( Color.BLACK ) );
      controlJPanel.setLayout( null );
      contentPane.add( controlJPanel );
      
      // set up displayJTextField
      displayJTextField = new JTextField();
      displayJTextField.setBounds( 7, 5, 135, 42 );
      displayJTextField.setText( "Microwave Oven" );
      displayJTextField.setHorizontalAlignment( JTextField.CENTER );
      displayJTextField.setEditable( false );
      controlJPanel.add( displayJTextField );

      // set up oneJButton
      oneJButton = new JButton();
      oneJButton.setBounds( 13, 59, 41, 24 );
      oneJButton.setText( "1" );
      controlJPanel.add( oneJButton );
      oneJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when oneJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               oneJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener
      
      // set up twoJButton
      twoJButton = new JButton();
      twoJButton.setBounds( 54, 59, 41, 24 );
      twoJButton.setText( "2" );
      controlJPanel.add( twoJButton );
      twoJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when twoJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               twoJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener

      // set up threeJButton
      threeJButton = new JButton();
      threeJButton.setBounds( 95, 59, 41, 24 );
      threeJButton.setText( "3" );
      controlJPanel.add( threeJButton );
      threeJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when threeJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               threeJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener

      // set up fourJButton
      fourJButton = new JButton();
      fourJButton.setBounds( 13, 83, 41, 24 );
      fourJButton.setText( "4" );
      controlJPanel.add( fourJButton );
      fourJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when fourJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               fourJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener

      // set up fiveJButton
      fiveJButton = new JButton();
      fiveJButton.setBounds( 54, 83, 41, 24 );
      fiveJButton.setText( "5" );
      controlJPanel.add( fiveJButton );
      fiveJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when fiveJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               fiveJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener

      // set up sixJButton
      sixJButton = new JButton();
      sixJButton.setBounds( 95, 83, 41, 24 );
      sixJButton.setText( "6" );
      controlJPanel.add( sixJButton );
      sixJButton.addActionListener(

         new ActionListener() // anonymous inner class
         {
            // event handler called when sixJButton is pressed
            public void actionPerformed( ActionEvent event )
            {
               sixJButtonActionPerformed( event );
            }

         } // end anonymous inner class

      ); // end call to addActionListener

      // set up sevenJButton
      sevenJButton = new JButton();
      sevenJButton.setBounds( 13, 107, 41, 24 );
      sevenJButton.setText( "7" );
      controlJPanel.add( sevenJButton );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -