java:点击按钮,改变label的文字!!!
怎样添加命令?importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclasshaibaoe...
怎样添加命令?import java.awt.*;import javax.swing.*;import java.awt.event.*;public class haibao extends JPanel implements ActionListener{ JFrame frame; int tag = 0; public static void main (String [ ] args){ haibao gui = new haibao(); gui.go(); } public void go(){ frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("换一张!"); frame.getContentPane().add(button,"South"); JLabel label1 = new JLabel("电影海报"); frame.getContentPane().add(label1, "North"); JLabel label2 = new JLabel("换一张"); frame.getContentPane().add(label2, "North"); frame.getContentPane().add(new haibao()); frame.setSize(1024, 576); frame.setVisible(true); } public void actionPerformed(ActionEvent event){ } public haibao(){ ImageIcon img = new ImageIcon("D:\\eclipse3\\works\\haibao\\src\\luhan.jpg"); JLabel jl = new JLabel(img); this.setLayout(new BorderLayout()); this.add(jl,BorderLayout.CENTER); } public void windowClosing(WindowEvent e){ System.exit(0); }}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询