不是抽象的,并且未覆盖 抽象方法 5
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;classMyWindowextendsJFram...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class MyWindow extends JFrame implements ActionListener
{
TextField textInput,textShow;
PoliceMan police;
MyWindow(String s)
{
super(s);
setLayout(new FlowLayout());
textInput=new TextField(10);
textShow=new TextField(10);
textShow.setEditable(false);
police=new PoliceMan();
add(textInput);
add(textShow);
textInput.addActionListener(this);
textInput.addActionListener(police);
setBounds(100,100,150,200);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==textInput)
{
int n=0,m=0;
try{
n=Integer.parseInt(textInput.getText());
m=n*n;
textShow.setText(n+"的平方是"+m);
}
catch(Exception ee)
{
textShow.setText("请输入数字");
textInput.setText(null);
}
}
}
}
class PoliceMan implements ActionListener
{
public void ActionPerformed(ActionEvent e)
{
int n=0,m=0;
String str=e.getActionCommand();
try{
n=Integer.parseInt(str);
m=n*n*n;
System.out.println(n+"的立方是"+m);
}
catch(Exception ee)
{
System.out.println(e.toString());
}
}
}
public class Example8_6
{
public static void main(String args)
{
MyWindow win=new MyWindow("窗口");
}
} 展开
import javax.swing.*;
import java.awt.event.*;
class MyWindow extends JFrame implements ActionListener
{
TextField textInput,textShow;
PoliceMan police;
MyWindow(String s)
{
super(s);
setLayout(new FlowLayout());
textInput=new TextField(10);
textShow=new TextField(10);
textShow.setEditable(false);
police=new PoliceMan();
add(textInput);
add(textShow);
textInput.addActionListener(this);
textInput.addActionListener(police);
setBounds(100,100,150,200);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==textInput)
{
int n=0,m=0;
try{
n=Integer.parseInt(textInput.getText());
m=n*n;
textShow.setText(n+"的平方是"+m);
}
catch(Exception ee)
{
textShow.setText("请输入数字");
textInput.setText(null);
}
}
}
}
class PoliceMan implements ActionListener
{
public void ActionPerformed(ActionEvent e)
{
int n=0,m=0;
String str=e.getActionCommand();
try{
n=Integer.parseInt(str);
m=n*n*n;
System.out.println(n+"的立方是"+m);
}
catch(Exception ee)
{
System.out.println(e.toString());
}
}
}
public class Example8_6
{
public static void main(String args)
{
MyWindow win=new MyWindow("窗口");
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询