两个关于applet的基础问题,在线等 1:用removeXXXListener()方法!2:要看具体情况啊,不知道你是什么情况! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 to zhutouzip:removeXXXListener是去掉某个诊听吧?我是想知道关闭页面的方法。在swing中我用的是System.exit(0)这个方法。但关页面应该不是这个吧,是否有对应的方法。=============================================这个就是具体的情况,哪位能帮我调一下吗,再次感谢import java.awt.*;import java.awt.event.*;import javax.swing.*;public class CalAppletPlus extends JApplet implements ActionListener{ private Frame f; private Panel p1,p2; private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16; private TextField t1; private MenuBar mb; private Menu m1; private MenuItem mitem1,mitem2; double x=0,y=0; char xx='c',yy='c';//记录运算符 StringBuffer str=new StringBuffer(); public static void main(String args[]) { Frame f=new Frame(); MenuBar mb=new MenuBar(); Menu m1=new Menu("Operate"); MenuItem mitem1=new MenuItem("Close"); CalAppletPlus cal=new CalAppletPlus(); f.add(cal, BorderLayout.CENTER); f.setMenuBar(mb); mb.add(m1); m1.add(mitem1); f.setSize (250, 150); f.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);} }); cal.init(); //cal.start(); f.setVisible(true); } public void init() { f=new Frame("Calculator"); p1=new Panel(); p2=new Panel(); t1=new TextField(); GridLayout layout=new GridLayout(4,4); b1=new Button("7"); b2=new Button("8"); b3=new Button("9"); b4=new Button("+"); b5=new Button("4"); b6=new Button("5"); b7=new Button("6"); b8=new Button("-"); b9=new Button("1"); b10=new Button("2"); b11=new Button("3"); b12=new Button("*"); b13=new Button("0"); b14=new Button("."); b15=new Button("="); b16=new Button("/"); mb=new MenuBar(); m1=new Menu("Operate"); mitem1=new MenuItem("Close"); mitem2=new MenuItem("hello"); p2.setLayout(layout); p2.add(b1); p2.add(b2); p2.add(b3); p2.add(b4); p2.add(b5); p2.add(b6); p2.add(b7); p2.add(b8); p2.add(b9); p2.add(b10); p2.add(b11); p2.add(b12); p2.add(b13); p2.add(b14); p2.add(b15); p2.add(b16); //setMenuBar(mb); //setLayout(bl); getContentPane().add(t1,BorderLayout.NORTH); getContentPane().add(p2,BorderLayout.CENTER); mb.add(m1); m1.add(mitem1); m1.addSeparator(); m1.add(mitem2); setSize(100,100); t1.setSize(100,100); setVisible(true); addListener(); } public void addListener() { b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); b7.addActionListener(this); b8.addActionListener(this); b9.addActionListener(this); b10.addActionListener(this); b11.addActionListener(this); b12.addActionListener(this); b13.addActionListener(this); b14.addActionListener(this); b15.addActionListener(this); b16.addActionListener(this); f.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);} }); mitem1.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="Close") { System.exit(0); } String ss=""; if(e.getActionCommand()=="+"||e.getActionCommand()=="-"||e.getActionCommand()=="*"||e.getActionCommand()=="/"||e.getActionCommand()=="=") { yy=xx; xx=e.getActionCommand().charAt(0); switch(yy) { case '+': x=x+y; if(xx=='=') { xx='c'; yy='c'; t1.setText(new Double(x).toString()); x=0; y=0; } else { t1.setText(new Double(x).toString()); } break; case '-': x=x-y; if(xx=='=') { xx='c'; yy='c'; t1.setText(new Double(x).toString()); x=0; y=0; } else { t1.setText(new Double(x).toString()); } break; case '*': x=x*y; if(xx=='=') { xx='c'; yy='c'; t1.setText(new Double(x).toString()); x=0; y=0; } else { t1.setText(new Double(x).toString()); } break; case '/': x=x/y; if(xx=='=') { xx='c'; yy='c'; t1.setText(new Double(x).toString()); x=0; y=0; } else { t1.setText(new Double(x).toString()); } break; default: x=y; } //end switch str.delete(0,str.length()); } else { ss=e.getActionCommand(); System.out.println(ss); str.append(ss); t1.setText(str.toString()); y=Double.parseDouble(str.toString()); } } } 老大,用的是哪个版的JDK啊?难道不需要java.applet.*这个包吗? TO:楼主:我已经帮你调过了,只要把那个包加上去就一切OK! 什么是钩子方法 java 字符集的问题 JCreator动态随笔问题 外行求助--大型机 请教如何获得JComboBox的内容 在JAVA中判断文件打开还是关闭 关闭其他JAR包中窗体的问题 高手请进!(关注者有分) 我没学过c++,学java会困难吗? applet中怎么跳到一个新的页面? 还是IO问题, 菜鸟求解 怎样把一个50*50象素的图形转化为24*24象素的,并且怎样才能保存到数据库中去?
removeXXXListener是去掉某个诊听吧?我是想知道关闭页面的方法。在swing中我用的是System.exit(0)这个方法。但关页面应该不是这个吧,是否有对应的方法。
=============================================这个就是具体的情况,哪位能帮我调一下吗,再次感谢
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class CalAppletPlus extends JApplet implements ActionListener
{
private Frame f;
private Panel p1,p2;
private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
private TextField t1;
private MenuBar mb;
private Menu m1;
private MenuItem mitem1,mitem2;
double x=0,y=0;
char xx='c',yy='c';//记录运算符
StringBuffer str=new StringBuffer();
public static void main(String args[])
{
Frame f=new Frame();
MenuBar mb=new MenuBar();
Menu m1=new Menu("Operate");
MenuItem mitem1=new MenuItem("Close");
CalAppletPlus cal=new CalAppletPlus();
f.add(cal, BorderLayout.CENTER);
f.setMenuBar(mb);
mb.add(m1);
m1.add(mitem1);
f.setSize (250, 150);
f.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
});
cal.init();
//cal.start();
f.setVisible(true);
}
public void init()
{
f=new Frame("Calculator");
p1=new Panel();
p2=new Panel();
t1=new TextField();
GridLayout layout=new GridLayout(4,4);
b1=new Button("7");
b2=new Button("8");
b3=new Button("9");
b4=new Button("+");
b5=new Button("4");
b6=new Button("5");
b7=new Button("6");
b8=new Button("-");
b9=new Button("1");
b10=new Button("2");
b11=new Button("3");
b12=new Button("*");
b13=new Button("0");
b14=new Button(".");
b15=new Button("=");
b16=new Button("/");
mb=new MenuBar();
m1=new Menu("Operate");
mitem1=new MenuItem("Close");
mitem2=new MenuItem("hello");
p2.setLayout(layout);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.add(b7);
p2.add(b8);
p2.add(b9);
p2.add(b10);
p2.add(b11);
p2.add(b12);
p2.add(b13);
p2.add(b14);
p2.add(b15);
p2.add(b16);
//setMenuBar(mb);
//setLayout(bl);
getContentPane().add(t1,BorderLayout.NORTH);
getContentPane().add(p2,BorderLayout.CENTER);
mb.add(m1);
m1.add(mitem1);
m1.addSeparator();
m1.add(mitem2);
setSize(100,100);
t1.setSize(100,100);
setVisible(true);
addListener();
}
public void addListener()
{
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
f.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}
});
mitem1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="Close")
{
System.exit(0);
}
String ss="";
if(e.getActionCommand()=="+"||e.getActionCommand()=="-"||e.getActionCommand()=="*"||e.getActionCommand()=="/"||e.getActionCommand()=="=")
{
yy=xx;
xx=e.getActionCommand().charAt(0);
switch(yy)
{
case '+':
x=x+y;
if(xx=='=')
{
xx='c';
yy='c';
t1.setText(new Double(x).toString());
x=0;
y=0;
}
else
{
t1.setText(new Double(x).toString());
}
break;
case '-':
x=x-y;
if(xx=='=')
{
xx='c';
yy='c';
t1.setText(new Double(x).toString());
x=0;
y=0;
}
else
{
t1.setText(new Double(x).toString());
}
break;
case '*':
x=x*y;
if(xx=='=')
{
xx='c';
yy='c';
t1.setText(new Double(x).toString());
x=0;
y=0;
}
else
{
t1.setText(new Double(x).toString());
}
break;
case '/':
x=x/y;
if(xx=='=')
{
xx='c';
yy='c';
t1.setText(new Double(x).toString());
x=0;
y=0;
}
else
{
t1.setText(new Double(x).toString());
}
break;
default:
x=y;
} //end switch
str.delete(0,str.length());
}
else
{
ss=e.getActionCommand();
System.out.println(ss);
str.append(ss);
t1.setText(str.toString());
y=Double.parseDouble(str.toString());
}
}
}
我已经帮你调过了,只要把那个包加上去就一切OK!