import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class Test
{
public static void main(String[] args)
{
JFrame F=new JFrame();
F.setSize(450, 450);
{
public static void main(String[] args)
{
JFrame F=new JFrame();
F.setSize(450, 450);
JTextField T=new JTextField(20);
JPanel P=new JPanel();
JButton B=new JButton("Button A");
B.setMnemonic(KeyEvent.VK_I); 按扭事件
B.addActionListener(new ActionListener() { 回傳
JPanel P=new JPanel();
JButton B=new JButton("Button A");
B.setMnemonic(KeyEvent.VK_I); 按扭事件
B.addActionListener(new ActionListener() { 回傳
public void actionPerformed(ActionEvent e) { 出現
T.setText("Button 1!");
}
});
T.setText("Button 1!");
}
});
JButton B1=new JButton("Button B");
B1.setMnemonic(KeyEvent.VK_I);
B1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
T.setText("Button 2!");
}
});
B.setBounds(20,20,100,40);
B1.setBounds(150,20,100,40);
T.setText("Button 2!");
}
});
B.setBounds(20,20,100,40);
B1.setBounds(150,20,100,40);
P.add(B);
P.add(B1);
P.add(T);
F.getContentPane().add(P,BorderLayout.CENTER);
F.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class ATest
{
public static void main(String[] args)
{
JFrame F=new JFrame();
F.setSize(450, 450);
JPanel P=new JPanel();
{
public static void main(String[] args)
{
JFrame F=new JFrame();
F.setSize(450, 450);
JPanel P=new JPanel();
JButton button[]=new JButton[10];
for (int i = 0; i < 9; i++){ for迴圈
button[i] = new JButton();
button[i].setSize(50,50);
button[i].setText(Integer.toString(i+1));
P.add(button[i]);
}
F.getContentPane().add(P,BorderLayout.CENTER);
F.setVisible(true);
}
}
沒有留言:
張貼留言