import javax.swing.*; import java.awt.event.*; import java.awt.*; class TouChaCol{ JFrame frame; JLabel label; public static void main(String [] args){ TouChaCol ch = new TouChaCol(); ch.go(); } class LabelActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ label.setText("fuck you click me"); } } class ColorActionListener implements ActionListener{ public void actionPerformed(ActionEvent e){ frame.repaint(); } } public void go(){ frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Panel panel = new Panel(); label = new JLabel("yoooyo helllo who are you"); JButton button1 = new JButton("change the color"); button1.addActionListener(new ColorActionListener()); JButton button2 = new JButton("change the label"); button2.addActionListener(new LabelActionListener()); frame.getContentPane().add(BorderLayout.SOUTH,button1); frame.getContentPane().add(BorderLayout.EAST,button2); frame.getContentPane().add(BorderLayout.WEST,label); frame.getContentPane().add(BorderLayout.CENTER,panel); frame.setSize(700, 700); frame.setVisible(true); } }
相关文章: