📄 panelapplet.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Color;
import javax.swing.*;
public class PanelApplet extends Applet implements
ActionListener,MouseListener,MouseMotionListener,ItemListener
{
int total=0;
public Button b2=new Button("submit");
public Button b3=new Button("key to questions");
RadioButtonTest r1 = new RadioButtonTest();
RadioButtonTest2 r2 = new RadioButtonTest2();
RadioButtonTest3 r3 = new RadioButtonTest3();
RadioButtonTest4 r4 = new RadioButtonTest4();
RadioButtonTest5 r5 = new RadioButtonTest5();
RadioButtonTest6 r6 = new RadioButtonTest6();
RadioButtonTest7 r7 = new RadioButtonTest7();
RadioButtonTest8 r8 = new RadioButtonTest8();
RadioButtonTest9 r9 = new RadioButtonTest9();
RadioButtonTest10 r10 = new RadioButtonTest10();
public Label RR = new Label();
public Label RO = new Label();
public Label RP = new Label();
//初始化
public void init()
{
setLayout(null);
addMouseListener(this);
add(b2);
b2.setBackground(Color.YELLOW);
b2.setBounds(700,650,100,30);
b2.addActionListener(this);
add(b3);
b3.setBackground(Color.YELLOW);
b3.setBounds(850,650,100,30);
b3.addActionListener(this);
add(r1);
r1.setBackground(Color.GREEN);
r1.setBounds(10,10,1000,60);
add(r2);
r2.setBounds(10,70,1000,60);
add(r3);
r3.setBounds(10,130,1000,60);
add(r4);
r4.setBounds(10,190,1000,60);
add(r5);
r5.setBounds(10,250,1000,60);
add(r6);
r6.setBounds(10,310,1000,60);
add(r7);
r7.setBounds(10,370,1000,60);
add(r8);
r8.setBounds(10,430,1000,60);
add(r9);
r9.setBounds(10,490,1000,60);
add(r10);
r10.setBounds(10,550,1000,60);
add(RR);
RR.setBounds(10,620,300,30);
add(RO);
RO.setBounds(10,650,800,50);
}
public void itemStateChanged(ItemEvent e)//监听checkBox
{
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b2)
{
total = r1.getValue()+r2.getValue()+r3.getValue()+r4.getValue()+r5.getValue()+
r6.getValue()+r7.getValue()+r8.getValue()+r9.getValue()+r10.getValue();
RR.setText("您一共答对了"+""+total+""+"道题! 得到了"+total+"分!!");
total = 0;
}
if (e.getSource()==b3)
{
RO.setText("1. B 2. B 3. C 4. A 5. A 6. C 7. D 8. A 9. B 10. A ");
}
}
public void paint(Graphics g)
{
setBackground(Color.WHITE);
}
public void mouseClicked(MouseEvent e){}//点击鼠标落下
public void mousePressed(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
}
//////////////////////////////////////////////////////////////////
class RadioButtonTest extends JApplet {
public JTextField field;
public Font plainFont, boldFont, italicFont, boldItalicFont;
public JRadioButton plainButton, boldButton, italicButton,
boldItalicButton;
public ButtonGroup radioGroup;
int t1 = 0;
// create GUI and fonts
public RadioButtonTest()
{
// get content pane and set its layout
Container container = getContentPane();
container.setLayout( new FlowLayout() );
// set up JTextField
field = new JTextField( "1.Where does Java stem from?",90);
field.setBackground(Color.GREEN);
container.add( field );
// create radio buttons
plainButton = new JRadioButton( "A. Ada", true );
container.add( plainButton );
boldButton = new JRadioButton( "B. C++", false );
container.add( boldButton );
italicButton = new JRadioButton( "C. Pasacal", false );
container.add( italicButton );
boldItalicButton = new JRadioButton( "D.BASIC", 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 t1;
}
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 ) t1 = 1;
else t1 =0;
field.setFont( font );
}
} // end public inner class RadioButtonHandler
} // end class RadioButtonTest
//////////////////////////////////////////////////////////////////
class RadioButtonTest2 extends JApplet {
public JTextField field;
public Font plainFont, boldFont, italicFont, boldItalicFont;
public JRadioButton plainButton, boldButton, italicButton,
boldItalicButton;
public ButtonGroup radioGroup;
public int t2=0;
// create GUI and fonts
public RadioButtonTest2()
{
// get content pane and set its layout
Container container = getContentPane();
container.setLayout( new FlowLayout() );
// set up JTextField
field = new JTextField( "2.Which of the following is correct? ", 90 );
field.setBackground(Color.YELLOW);
container.add( field );
// create radio buttons
plainButton = new JRadioButton( "A、 machine code comes after compiling ", true );
container.add( plainButton );
boldButton = new JRadioButton( "B、byte code comes after compiling", false );
container.add( boldButton );
italicButton = new JRadioButton( "C、DLL comes after compiling", false );
container.add( italicButton );
boldItalicButton = new JRadioButton( " D、none of the above ", 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 t2;
}
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 ) t2 = 1;
else t2=0;
field.setFont( font );
}
} // end public inner class RadioButtonHandler
} // end class RadioButtonTest
//////////////////////////////////////////////////////////////////
class RadioButtonTest3 extends JApplet {
public JTextField field;
public Font plainFont, boldFont, italicFont, boldItalicFont;
public JRadioButton plainButton, boldButton, italicButton,
boldItalicButton;
public ButtonGroup radioGroup;
public int t3;
// create GUI and fonts
public RadioButtonTest3()
{
//super( "RadioButton Test" );
// get content pane and set its layout
Container container = getContentPane();
container.setLayout( new FlowLayout() );
// set up JTextField
field = new JTextField( "3.which is correct( )?", 90 );
field.setBackground(Color.GREEN);
container.add( field );
// create radio buttons
plainButton = new JRadioButton( "A、constructor can not be omitted", true );
container.add( plainButton );
boldButton = new JRadioButton( " B、constructor must have the same name with its class", false );
container.add( boldButton );
italicButton = new JRadioButton( "C.constructor implements itself when in the period of new", false );
container.add( italicButton );
boldItalicButton = new JRadioButton( " D. a class can define only one constructor ", 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 t3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -