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

📄 panelapplet.java

📁 10道测试题GUI形式的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      container.add( plainButton );

      boldButton = new JRadioButton( "B.abstract method must use{ } ", false );
      container.add( boldButton );

      italicButton = new JRadioButton( "C. {} can be omitted ", false );
      container.add( italicButton );
	
      boldItalicButton = new JRadioButton( "D. it is necessary to use {} when declaring a varible", 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 t7;
   }

 

 
   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== boldItalicFont) t7 =1;
		  else t7 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

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

class RadioButtonTest8 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t8 = 0;
 
   // create GUI and fonts
   public RadioButtonTest8()
   {
      //super( "RadioButton Test" );

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

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

      // create radio buttons
      plainButton = new JRadioButton( "A. Formal parameter can be regarded as local variable", true );
      container.add( plainButton );

      boldButton = new JRadioButton( "B. Formal parameter can be ornamentd by string", false );
      container.add( boldButton );

      italicButton = new JRadioButton( "C. Formal parameter is the actual parameter when used", false );
      container.add( italicButton );

      boldItalicButton = new JRadioButton( "D. Formal parameter can not be an object", 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 t8;
}
   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 ) t8 =1;
            else t8 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

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

class RadioButtonTest9 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t9 = 0;
 
   // create GUI and fonts
   public RadioButtonTest9()
   {
      //super( "RadioButton Test" );

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

      // set up JTextField
      field = new JTextField( "9.Which of the following can be used to arrange the alignment?", 90 );
      field.setBackground(Color.GREEN);
      container.add( field ); 

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

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

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

      boldItalicButton = new JRadioButton( "D. FlowLayout", 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 t9;
}
   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 ==   boldFont) t9 =1;
            else t9 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

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

class RadioButtonTest10 extends JApplet {
   public JTextField field;
   public Font plainFont, boldFont, italicFont, boldItalicFont;
   public JRadioButton plainButton, boldButton, italicButton, 
      boldItalicButton;
   public ButtonGroup radioGroup;
   public int t10 = 0;
 
   // create GUI and fonts
   public RadioButtonTest10()
   {
      //super( "RadioButton Test" );

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

      // set up JTextField
      field = new JTextField( "10.How to define the feature of Java  ", 90 );
      field.setBackground(Color.YELLOW);
      container.add( field ); 

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

      boldButton = new JRadioButton( "B. Process Oriented Language", false );
      container.add( boldButton );

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

      boldItalicButton = new JRadioButton( "D. formal Language", 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 t10;
}
   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) t10 =1;
            else t10 =0;
         field.setFont( font );
      }

   } // end public inner class RadioButtonHandler

} // end class RadioButtonTest 

⌨️ 快捷键说明

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