请教关于JPanel addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } );这里有一个匿名类。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的top也没有在NotHelloWorldFrame里声明啊下面的NotHelloWorldPanel就是放在NotHelloWorldFrame里声明啊。import java.awt.*;import java.awt.event.*;import javax.swing.*;class NotHelloWorldFrame extends JFrame{ //NotHelloWorldPanel f; public NotHelloWorldFrame(){ setTitle("NotHelloWorld"); setSize(300, 200); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); Container contentPane = getContentPane(); contentPane.add(new NotHelloWorldPanel()); } class NotHelloWorldPanel extends JPanel{ public void paintComponent(Graphics g){ super.paintComponent(g); g.drawString("Not a Hello, World program", 75, 100); } }}public class NotHelloWorld{ public static void main(String[] args){ JFrame frame = new NotHelloWorldFrame(); frame.show(); }}class top extends JPanel{ JLabel label; public top(String str){ label=new JLabel("aaaa"); label.setFont(new Font("",1,20)); this.add(label); } } NotHelloWorldFrame$1.class这个类叫匿名类吗? class NotHelloWorldFrame extends JFrame{ NotHelloWorldPanel f; top g; public NotHelloWorldFrame(){ setTitle("NotHelloWorld"); setSize(300, 200); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } });top和NotHelloWorldPanel在NotHelloWorldFrame里声明但NotHelloWorldPanel f;却报错不知为什么 NotHelloWorldFrame$1.class叫做匿名类啊,因为没有指定类名,所以生成的class的名字就在所附着的有名类的后面加上$符号再加上序号,有第二个匿名类就是NotHelloWorldFrame$2.class没问题啊import java.awt.*;import java.awt.event.*;import javax.swing.*;class NotHelloWorldFrame extends JFrame{ NotHelloWorldPanel f; public NotHelloWorldFrame(){ setTitle("NotHelloWorld"); setSize(300, 200); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); Container contentPane = getContentPane(); contentPane.add(new NotHelloWorldPanel()); } class NotHelloWorldPanel extends JPanel{ public void paintComponent(Graphics g){ super.paintComponent(g); g.drawString("Not a Hello, World program", 75, 100); } }}public class NotHelloWorld{ public static void main(String[] args){ JFrame frame = new NotHelloWorldFrame(); frame.show(); }}class top extends JPanel{ JLabel label; public top(String str){ label=new JLabel("aaaa"); label.setFont(new Font("",1,20)); this.add(label); } } 不会有任何问题了import java.awt.*;import java.awt.event.*;import javax.swing.*;class NotHelloWorldPanel extends JPanel{ public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("Not a Hello, World program", 75, 100); }}class NotHelloWorldFrame extends JFrame{ NotHelloWorldPanel f; public NotHelloWorldFrame() { setTitle("NotHelloWorld"); setSize(300, 200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); Container contentPane = getContentPane(); contentPane.add(new NotHelloWorldPanel()); }}public class NotHelloWorld{ public static void main(String[] args) { JFrame frame = new NotHelloWorldFrame(); frame.show(); }}class top extends JPanel{ JLabel label; public top(String str) { label=new JLabel("aaaa"); label.setFont(new Font("",1,20)); this.add(label); } } google的translate接口被封后如何写翻译软件 一道程序题!! 请教:JTable中removeRow的问题 java 怎么画圆 Java数据结构 webwork与struts2.0 JDK5关于对集合范型声明的判断问题,狂人乱入 win2000下编译java程序看不到运行结果的问题,今天解决加到100分!!! 你们有哪位高手可以看懂这个啊 About JDBC2.0 & SQL3 菜鸟求救,高分享送!!! 怎么将类序列化
import java.awt.event.*;
import javax.swing.*;class NotHelloWorldFrame extends JFrame{
//NotHelloWorldPanel f;
public NotHelloWorldFrame(){
setTitle("NotHelloWorld");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}); Container contentPane = getContentPane();
contentPane.add(new NotHelloWorldPanel());
}
class NotHelloWorldPanel extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawString("Not a Hello, World program", 75, 100);
}
}}public class NotHelloWorld{
public static void main(String[] args){
JFrame frame = new NotHelloWorldFrame();
frame.show();
}
}class top extends JPanel{
JLabel label;
public top(String str){
label=new JLabel("aaaa");
label.setFont(new Font("",1,20));
this.add(label);
}
}
这个类叫匿名类吗?
NotHelloWorldPanel f;
top g;
public NotHelloWorldFrame(){
setTitle("NotHelloWorld");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
top和NotHelloWorldPanel在NotHelloWorldFrame里声明但NotHelloWorldPanel f;却报错不知为什么
叫做匿名类啊,因为没有指定类名,所以生成的class的名字就在所附着的有名类的后面加上$符号再加上序号,有第二个匿名类就是NotHelloWorldFrame$2.class没问题啊import java.awt.*;
import java.awt.event.*;
import javax.swing.*;class NotHelloWorldFrame extends JFrame{
NotHelloWorldPanel f;
public NotHelloWorldFrame(){
setTitle("NotHelloWorld");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}); Container contentPane = getContentPane();
contentPane.add(new NotHelloWorldPanel());
}
class NotHelloWorldPanel extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawString("Not a Hello, World program", 75, 100);
}
}}public class NotHelloWorld{
public static void main(String[] args){
JFrame frame = new NotHelloWorldFrame();
frame.show();
}
}class top extends JPanel{
JLabel label;
public top(String str){
label=new JLabel("aaaa");
label.setFont(new Font("",1,20));
this.add(label);
}
}
不会有任何问题了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;class NotHelloWorldPanel extends JPanel
{ public void paintComponent(Graphics g)
{ super.paintComponent(g);
g.drawString("Not a Hello, World program", 75, 100);
}
}class NotHelloWorldFrame extends JFrame
{ NotHelloWorldPanel f;
public NotHelloWorldFrame()
{ setTitle("NotHelloWorld");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} ); Container contentPane = getContentPane();
contentPane.add(new NotHelloWorldPanel());
}
}public class NotHelloWorld
{ public static void main(String[] args)
{ JFrame frame = new NotHelloWorldFrame();
frame.show();
}
}class top extends JPanel
{
JLabel label;
public top(String str)
{
label=new JLabel("aaaa");
label.setFont(new Font("",1,20));
this.add(label);
}
}