eclipse中运行Applet什么都没有,环境配置好了。运行连1都没输出。 init方法都没执行 70
packagemyview;importjava.applet.*;importjava.awt.Color;importjava.awt.event.ActionEve...
package myview;
import java.applet.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.StringTokenizer;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class BookExample extends Applet implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
JTextArea textA;
JTextField textF;
JButton b1,b2;
public void init(){
System.out.println(1);
setSize(250,150);
textA = new JTextArea("",5,10);
textA.setBackground(Color.cyan);
textF = new JTextField("",10);
textF.setBackground(Color.pink);
b1 = new JButton("求 和");
b2 = new JButton("重新开始");
textF.setEditable(false);
b1.addActionListener(this);
b2.addActionListener(this);
add(textA);
add(textF);
add(b1);
add(b2);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1){
String s = textA.getText();
StringTokenizer tokens = new StringTokenizer(s);
//使用默认的分隔符几何:空格、换行、Tab符合回车作分隔符
int n = tokens.countTokens(),sum=0,i;
for(i=0;i<=n-1;i++){
String temp = tokens.nextToken();//从文本区取下一个数据
sum+=Integer.parseInt(temp);
}
textF.setText(""+sum);
}else {
if(e.getSource()==b2){
textA.setText(null);
textF.setText(null);
}
}
}
} 展开
import java.applet.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.StringTokenizer;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class BookExample extends Applet implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
JTextArea textA;
JTextField textF;
JButton b1,b2;
public void init(){
System.out.println(1);
setSize(250,150);
textA = new JTextArea("",5,10);
textA.setBackground(Color.cyan);
textF = new JTextField("",10);
textF.setBackground(Color.pink);
b1 = new JButton("求 和");
b2 = new JButton("重新开始");
textF.setEditable(false);
b1.addActionListener(this);
b2.addActionListener(this);
add(textA);
add(textF);
add(b1);
add(b2);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1){
String s = textA.getText();
StringTokenizer tokens = new StringTokenizer(s);
//使用默认的分隔符几何:空格、换行、Tab符合回车作分隔符
int n = tokens.countTokens(),sum=0,i;
for(i=0;i<=n-1;i++){
String temp = tokens.nextToken();//从文本区取下一个数据
sum+=Integer.parseInt(temp);
}
textF.setText(""+sum);
}else {
if(e.getSource()==b2){
textA.setText(null);
textF.setText(null);
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询