Java高手请帮我看一下这个程序哪里有错???

2025-05-17 02:24:32
推荐回答(3个)
回答1:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class UseJLabel extends JFrame{
private int n=0;
private CardLayout cl=new CardLayout();
private JLabel cardLabel;
private Icon[] icons=new ImageIcon[12];
private JButton b1=new JButton("第一张");
private JButton b2=new JButton("下一张");
private JButton b3=new JButton("上一张");
private JButton b4=new JButton("最后一张");
public UseJLabel()
{
setLayout(new BorderLayout());
for(int i=0;i<12;i++)
icons[i]=new ImageIcon("images/T"+i+".gif");
cardLabel=new JLabel(icons[0]);
add (cardLabel);

JPanel jp=new JPanel();
jp.setLayout(new FlowLayout());
jp.add(b1);
jp.add(b2);
jp.add(b3);
jp.add(b4);
b3.setEnabled(false);
add(jp,BorderLayout.SOUTH);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
n=0;
cardLabel.setIcon(icons[n]);
b2.setEnabled(true);
b3.setEnabled(false);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cardLabel.setIcon(icons[++n]);
if(n==1) b3.setEnabled(true);
if(n==icons.length-1) b2.setEnabled(false);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
cardLabel.setIcon(icons[--n]);
if(n==icons.length-2) b2.setEnabled(true);
if(n==0) b3.setEnabled(false);
}
});
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
n=icons.length-1;
cardLabel.setIcon(icons[n]);
b2.setEnabled(false);
b3.setEnabled(true);
}
});
}

public static void main(String[] args){
UseJLabel frame=new UseJLabel();
frame.setTitle("测试JLabel");
frame.setSize(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

调好了,竟然报了20多处错误

回答2:

请写出错误内容

回答3:

public UseJLabel() ,这个是什么啊?方法?类?
我觉得括号有点乱了