日期:2014-05-20 浏览次数:20754 次
import javax.swing.*; import java.awt.*; import static net.mindview.util.SwingConsole.*; public class Button1 extends JFrame{ /** * @param args */ private JButton b1 = new JButton("Button 1"), b2 = new JButton("Button 2"); public Button1(){ setLayout(new FlowLayout()); add(b1); add(b2); } public static void main(String[] args) { // TODO Auto-generated method stub run(new Button1(),400,600); } }
import javax.swing.*; import java.awt.*; import java.awt.event.*; import net.mindview.util.SwingConsole; public class ex05 extends JFrame { /** * @param args */ private JButton b1 = new JButton("Button 1"), b2 = new JButton("Button 2"), b3 = new JButton("Button 3"); private JTextField txt = new JTextField(10); private ActionListener bl = new ActionListener(){ public void actionPerformed(ActionEvent e){ String name = ((JButton)e.getSource()).getText(); txt.setText(name); } }; public ex05(){ b1.addActionListener(bl); b2.addActionListener(bl); b3.addActionListener(bl); setLayout(new FlowLayout()); add(b1); add(b2); add(b3); } public static void main(String[] args) { // TODO Auto-generated method stub run(new ex05(), 400, 200); } }
JFrame jf=new ex05(); run(jf,400, 200);