问个一个小小小问题,我揭帖出名的快! 构造方法能显式的调用吗?还是提供下MyFrame类看看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 a.MyFrame();这个是错的吧。楼主能编译通过嘛? 晕,诸位!这是从书上抄下来的例程,我也编译通过啦,a.MyFrame();这种用法确实是对的,如果把它去掉程序反而不能正常执行。 你不是结帖出名得快吗?怎么还没结帖啊?比俺这个不出名的还慢。:(哦,那应该是MyFrame还有一个静态(static)方法叫MyFrame吧?除此之外,想不出别的情况了。 下面是MyFrame类的代码:import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.io.*; public class MyFrame extends JFrame implements ActionListener{ JButton button1,button2; Container con; void MyFrame() { con=getContentPane(); button1=new JButton("打开"); button2=new JButton("关闭"); con.setLayout(new FlowLayout()); con.add(button1); con.add(button2); pack(); setVisible(true); button1.addActionListener(this); button2.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { } if(e.getSource()==button2) System.exit(0); } } void MyFrame() //有返回值,根本不是构造函数,不知道这样写有什么意义 { con=getContentPane(); button1=new JButton("打开"); button2=new JButton("关闭"); con.setLayout(new FlowLayout()); con.add(button1); con.add(button2); pack(); setVisible(true); button1.addActionListener(this); button2.addActionListener(this); } 把函数名改成init()更好,免的引起误解 哦,还有种情况,就是MyFrame的父类种有个方法叫:MyFrame java中子类继承父类的构造方法吗? 哪个网站的博客支持桌面软件编辑好了,然后一把上传。 java.util.Calendar 类的使用,请教 寻找java提取大文件中一段字符串的最快的算法 关于文件的上传下载问题,敬赠100分 一个applet关于路径的问题,急急急!!! 请问如何从字节数组里取出某一范围的数据 关于输入的问题 Java新手求助: 请问有没有用java分析二进制文件(有文件格式的)的例子,多谢了!!!!! 关于JAR文件…… JApplet中paint()方法中super.paitn(g)的疑惑
import java.awt.event.*;
import java.awt.*;
import java.io.*;
public class MyFrame extends JFrame implements ActionListener
{
JButton button1,button2;
Container con;
void MyFrame()
{
con=getContentPane();
button1=new JButton("打开");
button2=new JButton("关闭");
con.setLayout(new FlowLayout());
con.add(button1);
con.add(button2);
pack();
setVisible(true);
button1.addActionListener(this);
button2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
}
if(e.getSource()==button2) System.exit(0);
}
}
{
con=getContentPane();
button1=new JButton("打开");
button2=new JButton("关闭");
con.setLayout(new FlowLayout());
con.add(button1);
con.add(button2);
pack();
setVisible(true);
button1.addActionListener(this);
button2.addActionListener(this);
}