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

📄 panelapplet.java

📁 10道测试题GUI形式的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   }

 

 
   public class RadioButtonHandler implements ItemListener {
      public Font font;

      public RadioButtonHandler( Font f )
      { 
         font = f;
      }
           
      // handle radio button events
      public void itemStateChanged( ItemEvent event )
      {
		  if(font == italicFont) t3 = 1;
	  else t3 = 0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

} // end class RadioButtonTest 
////////////////////////////////////////////////////////////////////////

class RadioButtonTest4 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t4 = 0;

   // create GUI and fonts
   public RadioButtonTest4()
   {
      //super( "RadioButton Test" );

      // get content pane and set its layout
      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      // set up JTextField
      field = new JTextField( "4.which packet has the ability to extract database from Java( )", 90 );
      field.setBackground(Color.YELLOW);
      container.add( field ); 

      // create radio buttons
      plainButton = new JRadioButton( "A.java.sql", true );
      container.add( plainButton );

      boldButton = new JRadioButton( " B.java.awt ", false );
      container.add( boldButton );

      italicButton = new JRadioButton( "C.java.lang ", false );
      container.add( italicButton );

      boldItalicButton = new JRadioButton( "  D.java.swing ", false );
      container.add( boldItalicButton );

      plainButton.setSelected(false);

      // create logical relationship between JRadioButtons
      radioGroup = new ButtonGroup();
      radioGroup.add( plainButton );
      radioGroup.add( boldButton );
      radioGroup.add( italicButton );
      radioGroup.add( boldItalicButton );

      // create font objects
      plainFont = new Font( "Serif", Font.PLAIN, 14 );
      boldFont = new Font( "Serif", Font.PLAIN, 14 );
      italicFont = new Font( "Serif", Font.PLAIN, 14 );
      boldItalicFont = new Font( "Serif", Font.PLAIN, 14 );
      field.setFont( plainFont );  // set initial font
      
      // register events for JRadioButtons
      plainButton.addItemListener( new RadioButtonHandler( plainFont ) );
      boldButton.addItemListener( new RadioButtonHandler( boldFont ) );
      italicButton.addItemListener( 
         new RadioButtonHandler( italicFont ) );
      boldItalicButton.addItemListener( 
         new RadioButtonHandler( boldItalicFont ) );

      setSize( 300, 100 );
      setVisible( true );

   } // end RadioButtonTest constructor

 public int getValue() {
return t4;
 }

 
   public class RadioButtonHandler implements ItemListener {
      public Font font;

      public RadioButtonHandler( Font f )
      {
		  
         font = f;
      }
           
      // handle radio button events
      public void itemStateChanged( ItemEvent event )
      {
		  if (font == plainFont)
		  {
			  t4=1;
		  }
		  else t4 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

} // end class RadioButtonTest 
/////////////////////////////////////////////////////////////////////

class RadioButtonTest5 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t5 = 0;

   // create GUI and fonts
   public RadioButtonTest5()
   {
      //super( "RadioButton Test" );

      // get content pane and set its layout
      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      // set up JTextField
      field = new JTextField( "5.Which of the following is grammatically correct( )", 90 );
      field.setBackground(Color.GREEN);
      container.add( field ); 

      // create radio buttons
      plainButton = new JRadioButton( "A.&& ", true );
      container.add( plainButton );

      boldButton = new JRadioButton( " B.<>", false );
      container.add( boldButton );

      italicButton = new JRadioButton( " C.if", false );
      container.add( italicButton );

      boldItalicButton = new JRadioButton( " D.:= ", false );
      container.add( boldItalicButton );

	  plainButton.setSelected(false);

      // create logical relationship between JRadioButtons
      radioGroup = new ButtonGroup();
      radioGroup.add( plainButton );
      radioGroup.add( boldButton );
      radioGroup.add( italicButton );
      radioGroup.add( boldItalicButton );

      // create font objects
      plainFont = new Font( "Serif", Font.PLAIN, 14 );
      boldFont = new Font( "Serif", Font.PLAIN, 14 );
      italicFont = new Font( "Serif", Font.PLAIN, 14 );
      boldItalicFont = new Font( "Serif", Font.PLAIN, 14 );
      field.setFont( plainFont );  // set initial font
      
      // register events for JRadioButtons
      plainButton.addItemListener( new RadioButtonHandler( plainFont ) );
      boldButton.addItemListener( new RadioButtonHandler( boldFont ) );
      italicButton.addItemListener( 
         new RadioButtonHandler( italicFont ) );
      boldItalicButton.addItemListener( 
         new RadioButtonHandler( boldItalicFont ) );

      setSize( 300, 100 );
      setVisible( true );

   } // end RadioButtonTest constructor

   public int getValue(){
	   return t5;
   
   }

 

 
   public class RadioButtonHandler implements ItemListener {
      public Font font;

      public RadioButtonHandler( Font f )
      {
 
	
         font = f;
      }
           
      // handle radio button events
      public void itemStateChanged( ItemEvent event )
      {
		 if(font == plainFont )  t5 =1;
		  else t5 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

} // end class RadioButtonTest 
/////////////////////////////////////////////////////////////////////////

class RadioButtonTest6 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t6 =0 ;

   // create GUI and fonts
   public RadioButtonTest6()
   {
      //super( "RadioButton Test" );

      // get content pane and set its layout
      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      // set up JTextField
      field = new JTextField( "6.after the program: a=0;c=0;  do{ --c; a=a-1; }while(a>0);  the value of C is( )", 90 );
      field.setBackground(Color.YELLOW);
      container.add( field ); 

      // create radio buttons
      plainButton = new JRadioButton( "A. 0", true );
      container.add( plainButton );

      boldButton = new JRadioButton( "B. 1", false );
      container.add( boldButton );

      italicButton = new JRadioButton( "C. -1", false );
      container.add( italicButton );

      boldItalicButton = new JRadioButton( "D. endless loop", false );
      container.add( boldItalicButton );

	  plainButton.setSelected(false);

      // create logical relationship between JRadioButtons
      radioGroup = new ButtonGroup();
      radioGroup.add( plainButton );
      radioGroup.add( boldButton );
      radioGroup.add( italicButton );
      radioGroup.add( boldItalicButton );

      // create font objects
      plainFont = new Font( "Serif", Font.PLAIN, 14 );
      boldFont = new Font( "Serif", Font.PLAIN, 14 );
      italicFont = new Font( "Serif", Font.PLAIN, 14 );
      boldItalicFont = new Font( "Serif", Font.PLAIN, 14 );
      field.setFont( plainFont );  // set initial font
      
      // register events for JRadioButtons
      plainButton.addItemListener( new RadioButtonHandler( plainFont ) );
      boldButton.addItemListener( new RadioButtonHandler( boldFont ) );
      italicButton.addItemListener( 
         new RadioButtonHandler( italicFont ) );
      boldItalicButton.addItemListener( 
         new RadioButtonHandler( boldItalicFont ) );

      setSize( 300, 100 );
      setVisible( true );

   } // end RadioButtonTest constructor

   public int getValue(){
   return t6;
   }

 

 
   public class RadioButtonHandler implements ItemListener {
      public Font font;

      public RadioButtonHandler( Font f )
      {
 

		 font = f;
      }
           
      // handle radio button events
      public void itemStateChanged( ItemEvent event )
      {
		  if(font == italicFont )  t6 =1;
		  else t6 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

} // end class RadioButtonTest 
////////////////////////////////////////////////////////////////////////////

class RadioButtonTest7 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t7 = 0;

   // create GUI and fonts
   public RadioButtonTest7()
   {
      //super( "RadioButton Test" );

      // get content pane and set its layout
      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      // set up JTextField
      field = new JTextField( "7.which of the following is correct( )?", 90 );
      field.setBackground(Color.GREEN);
      container.add( field ); 

      // create radio buttons
      plainButton = new JRadioButton( "A.abstract  can describe class ", true );

⌨️ 快捷键说明

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