双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

错误?

zuoyangguang zuoyangguang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package com.bruceeckel.swing;
import javax.swing.*;
import java.awt.event.*;

public class Console{
public static String title(Object o){
String t = o.getClass().toString();

if(t.indexOf("class") != -1)
t = t.substring(6);

return t;
}

public static void setupClosing(JFrame frame){
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}

public static void run(JFrame frame,int width,int height){
setupClosing(frame);
frame.setSize(width,height);
frame.setVisible(true);
}

public static void run(JApplet applet,int width,int height){
JFrame frame = new JFrame(title(applet));
setupClosing(frame);
frame.getContentPane().add(applet);
frame.setSize(width,height);
applet.init();
applet.start();
frame.setVisible(true);
}

public static void run(JPanel panel,int width,int height){
JFrame frame = new JFrame(title(panel));
setupClosing(frame);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}

编译没问题:

import javax.swing.*;
import java.awt.*;
import com.bruceeckel.swing.*;

public class Appletlc extends JApplet{
public void init(){
getContentPane().add(new JLabel("Applet!"));
}
public static void main(String[] args){
JApplet applet = new Appletlc();
JFrame frame = new JFrame("Appletlc");
Console.setupClosing(frame);
frame.getContentPane().add(applet);
frame.setSize(100,50);
applet.init();
applet.start();
frame.setVisible(true);
}
}
编译错误为:
G:\My Documents\Appletlc.java:12: cannot resolve symbol
symbol : method setupClosing (javax.swing.JFrame)
location: class Console
Console.setupClosing(frame);
^
1 error
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
zuoyangguang
Java SE 62,621 成员 307,251 内容