我好像并没有错呀 但它好提示我找不到符号DecoratedFrame import java.awt.*;
import javax.swing.*; public class Aaa extends JFrame
{
public void DecoratedFrame()
{
this.getContentPane().add(new JLabel("Just a test."));
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
this.setSize(300,150);
}
public static void main(String[] args)
{
JFrame frame = new DecoratedFrame();
frame.setVisible(true);
}
}开始说
public DecoratedFrame()
需要返回值 我就改成了
public void DecoratedFrame()
又说找不到DecoratedFrame()了
我承认我菜 可你也不能这样对我呀!找不到你想办法找呀 我都找到了你还找不到 都快被气死了
import javax.swing.*; public class Aaa extends JFrame
{
public void DecoratedFrame()
{
this.getContentPane().add(new JLabel("Just a test."));
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
this.setSize(300,150);
}
public static void main(String[] args)
{
JFrame frame = new DecoratedFrame();
frame.setVisible(true);
}
}开始说
public DecoratedFrame()
需要返回值 我就改成了
public void DecoratedFrame()
又说找不到DecoratedFrame()了
我承认我菜 可你也不能这样对我呀!找不到你想办法找呀 我都找到了你还找不到 都快被气死了
DecoratedFrame()是一个方法又不是一个类
怎么可以new
所以要让Aaa和DecoratedFrame名称一致
也就是说
可以写成如下情况:import java.awt.*;
import javax.swing.*; public class DecoratedFrame extends JFrame
{
public DecoratedFrame()
{
this.getContentPane().add(new JLabel("Just a test."));
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
this.setSize(300,150);
}
public static void main(String[] args)
{
JFrame frame = new DecoratedFrame();
frame.setVisible(true);
}
}
错误太明显了,你怎么new了一个方法啊 !
呵呵
把你的类名改成DecoratedFrame就好了
new后边跟的是类名。new出来的必须是一个类的对象,你写的是new它的成员方法。
main方法快里应该改成: JFrame frame = new ;
// 调用类的成员方法。
frame.DecoratedFrame();
// 显示
frame.setVisible(true);