我刚刚回到编程Swing和java一般,并且非常生疏。我试图完成的程序似乎是通过eclipse进行编译,但它不会运行,它告诉我它没有主要类型。而且它没有给我一个错误通知,所以我现在有点卡在这里。
我从来没有见过这个错误,所以不确定它是什么,或者不记得它是什么,如果我有。任何想法我做错了或应该修复让这个运行,谢谢:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Timer;
import javax.swing.Timer.*;
import javax.swing.event.*;
public class FamousLocations extends JFrame implements ChangeListener, ActionListener, Runnable
{
private static final long serialVersionUID = 0;
JMenuBar p = new JMenuBar();
int Selected = 0;
ImageIcon a = new ImageIcon("america.jpg");
ImageIcon j = new ImageIcon("Japan.jpg");
ImageIcon c = new ImageIcon("china.jpg");
ImageIcon i = new ImageIcon("ireland.jpg");
ImageIcon t = new ImageIcon("thailand.jpg");
ImageIcon ca = new ImageIcon("Niagra-Falls.jpg");
Icon[] pics = {a,j,c,i,t,ca};
private JLabel ImageLabel = new JLabel(pics[Selected]);
String america = ("Grand Canyon, America");
String japan = ("Kinkaku-ji (The Golden Pavilion) Kyoto, Japan");
String china = ("Mount Huangshan, China");
String ireland = ("Newgrange, Ireland");
String thailand = ("Bangkok ,Thailand");
String canada = ("Niagra Falls , Canada");
String[] Box = {america, japan, china, ireland, thailand, canada};
JTextArea lo = new JTextArea(Box[Selected]);
String InfoGrand = new String ("desciption");
String InfoHiro = new String ("desciption");
String InfoMount = new String ("desciption");
String InfoNew = new String ("desciption");
String InfoBang = new String ("desciption");
String InfoNiag = new String ("desciption");
String[] Info = {InfoGrand, InfoHiro, InfoMount, InfoNew, InfoBang, InfoNiag};
JTextArea ta = new JTextArea(Info[Selected]);
private JTabbedPane tp = new JTabbedPane();
public JSlider slider = new JSlider();
private JPanel dropd = new JPanel();
private JPanel checkb = new JPanel();
private JPanel ImagePan = new JPanel();
private JPanel InfoPan = new JPanel();
private JCheckBox slider1 = new JCheckBox ("Show Slider" , true);
private JCheckBox slideshow1 = new JCheckBox ("Slideshow", false);
JComboBox com1 = new JComboBox(Box);
public FamousLocations(){
setTitle("My Bucket List");
getContentPane().setLayout(new BorderLayout());
getContentPane().setBackground(Color.white);
getContentPane().setSize(1000,1000);
getContentPane().add(dropd);
getContentPane().add(slider,BorderLayout.SOUTH);
getContentPane().add(slider1);
getContentPane().add(slideshow1);
getContentPane().add(tp);
slider.setValue(0);
slider.addChangeListener(this);
slider.setOrientation(JSlider.HORIZONTAL);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
slider.setMajorTickSpacing(1);
slider.setMaximum(5);
slider.setSnapToTicks(true);
ImagePan.add(ImageLabel);
checkb.add(com1);
checkb.add(slider1);
checkb.add(slideshow1);
tp.addTab("Photo", ImagePan);
tp.addTab("Description of Area", InfoPan);
tp.addTab("Index and Options", checkb);
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setVisible(true);
ta.setSize(400,400);
slider1.setVisible(true);
slider1.addActionListener(this);
slideshow1.setVisible(true);
slideshow1.addActionListener(this);
com1.addActionListener(this);
com1.addActionListener(this);
JMenu help = new JMenu("HELP");
JMenuItem AL1 = help.add("how to use");
JMenuItem AL2 = help.add("EXIT");
p.add(help);
this.setJMenuBar(p);
AL1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,"error");
}
});
AL2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
setSize(250,250);
setVisible(true);
}
public void change(){
JTextArea ta=new JTextArea(Box[Selected]);
ImagePan.removeAll();
ImagePan.add(ImageLabel=new JLabel(pics[Selected]));
InfoPan.removeAll();
InfoPan.add(ImageLabel=new JLabel(Info[Selected]));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setVisible(true);
ta.setSize(400,400);
ImagePan.repaint();
validateTree();
}
public void run(){
for(int y = 0;y==y+1; y++){
slider.setValue(y);
try{
Thread.sleep (1000);
}
catch (Exception e) {}
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==slider1) {slider.setVisible(slider1.isSelected());}
else if(e.getSource()==com1)
{Selected=com1.getSelectedIndex(); change();}
else if(e.getSource()==slideshow1)
{new Thread(this).start(); }
}
public void stateChanged(ChangeEvent e) {
if(e.getSource()==slider){Selected=slider.getValue();change();}
}
}