当前位置: 技术问答>java相关
送分啦!!!
来源: 互联网 发布时间:2015-01-29
本文导语: //===================== MyFrame.java ======================= import java.awt.*; import javax.swing.*; import java.awt.event.*; import MyWindowListener; public class MyFrame extends JFrame { Container c; String closeOperationName[] = { "WindowCo...
//===================== MyFrame.java =======================
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import MyWindowListener;
public class MyFrame extends JFrame
{
Container c;
String closeOperationName[] =
{
"WindowConstants.DO_NOTHING_ON_CLOSE",
"WindowConstants.HIDE_ON_CLOSE",
"WindowConstants.DISPOSE_ON_CLOSE"
};
public MyFrame()
{
super("MyFrame.java: JFrame代刚");
c = getContentPane();
setSize(450, 140);
show();
}
public void paint( Graphics g )
{
g.setFont(new Font("Serif",Font.BOLD,14));
g.drawString("JFrame: " + paramString(), 10,50);
g.drawString("Container: " + c.toString(), 10,80);
g.drawString("Close Operation: " +
closeOperationName[getDefaultCloseOperation()],10,110);
}
public static void main( String args[] )
{
MyFrame app = new MyFrame();
app.addWindowListener(new MyWindowListener());
}
}
编译时,居然出现错误!!!!(这是书本的例子!)
错误提示:
c:jdk1.4bin>javac MyFrame.java
MyFrame.java:5:'.' expected
import MyWindowListener;
MyFrame.java:33:cannot resolve symbol
symbol : class MyWindowListener
Location : class MyFrame
app.addWindowListener(new MyWindowListener());
2 errors
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import MyWindowListener;
public class MyFrame extends JFrame
{
Container c;
String closeOperationName[] =
{
"WindowConstants.DO_NOTHING_ON_CLOSE",
"WindowConstants.HIDE_ON_CLOSE",
"WindowConstants.DISPOSE_ON_CLOSE"
};
public MyFrame()
{
super("MyFrame.java: JFrame代刚");
c = getContentPane();
setSize(450, 140);
show();
}
public void paint( Graphics g )
{
g.setFont(new Font("Serif",Font.BOLD,14));
g.drawString("JFrame: " + paramString(), 10,50);
g.drawString("Container: " + c.toString(), 10,80);
g.drawString("Close Operation: " +
closeOperationName[getDefaultCloseOperation()],10,110);
}
public static void main( String args[] )
{
MyFrame app = new MyFrame();
app.addWindowListener(new MyWindowListener());
}
}
编译时,居然出现错误!!!!(这是书本的例子!)
错误提示:
c:jdk1.4bin>javac MyFrame.java
MyFrame.java:5:'.' expected
import MyWindowListener;
MyFrame.java:33:cannot resolve symbol
symbol : class MyWindowListener
Location : class MyFrame
app.addWindowListener(new MyWindowListener());
2 errors
|
ok!
把import MyWindowListener;去掉!
试一试!
把import MyWindowListener;去掉!
试一试!
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。