物件Object
類別Class
屬性Property
事件Event
行為behavior
方法method
實際做出例子:
import javax.swing.*;
import java.awt.event.*;
public class Exe extends JFrame
implements ActionListener {
int SizeW = 500;
int SizeH = 500;
public static void main(String[] args) {
Exe test = new Exe();
}
public Exe() {
setTitle("9730029");
JButton mybutton = new JButton("Click");
JButton mybutton1 = new JButton("c");
JRadioButton mybutton2 = new JRadioButton("Yes");
JCheckBox mybutton3 = new JCheckBox("No");
mybutton.setSize(100,100);
mybutton.addActionListener(this);
/**mybutton.setBounds(1, 1, 1, 1);
mybutton1.setBounds(800, 1, 800, 1);
mybutton2.setBounds(1, 800, 1, 800);
mybutton3.setBounds(800, 800, 800, 800);**/
getContentPane().add(mybutton3);
getContentPane().add(mybutton);
getContentPane().add(mybutton1);
getContentPane().add(mybutton2);
//getContentPane().add(mybutton3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(SizeW,SizeH);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
SizeW = SizeW * 1;
SizeH = SizeH * 2;
setSize(SizeW,SizeH);
}
}
沒有留言:
張貼留言