当前位置: 技术问答>java相关
在JDK的教学里,所有的SWING APPLICATION都无法动行提示是这样,怎么回事?
来源: 互联网 发布时间:2015-04-06
本文导语: Exception in thread "main" java.lang.NoClassDefFoundError: topleveldemo import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TopLevelDemo { public static void main(String s[]) { JFrame frame = new JFrame("TopLevel...
Exception in thread "main" java.lang.NoClassDefFoundError: topleveldemo
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TopLevelDemo {
public static void main(String s[]) {
JFrame frame = new JFrame("TopLevelDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JLabel yellowLabel = new JLabel("");
yellowLabel.setOpaque(true);
yellowLabel.setBackground(Color.yellow);
yellowLabel.setPreferredSize(new Dimension(200, 180));
JMenuBar cyanMenuBar = new JMenuBar();
cyanMenuBar.setOpaque(true);
cyanMenuBar.setBackground(Color.cyan);
cyanMenuBar.setPreferredSize(new Dimension(200, 20));
frame.setJMenuBar(cyanMenuBar);
frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TopLevelDemo {
public static void main(String s[]) {
JFrame frame = new JFrame("TopLevelDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JLabel yellowLabel = new JLabel("");
yellowLabel.setOpaque(true);
yellowLabel.setBackground(Color.yellow);
yellowLabel.setPreferredSize(new Dimension(200, 180));
JMenuBar cyanMenuBar = new JMenuBar();
cyanMenuBar.setOpaque(true);
cyanMenuBar.setBackground(Color.cyan);
cyanMenuBar.setPreferredSize(new Dimension(200, 20));
frame.setJMenuBar(cyanMenuBar);
frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
|
java -classpath . TopLevelDemo
注意不要打错,区分大小写
注意不要打错,区分大小写