import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class IntFieldTester extends JPanel implements ActionListener{
public static final int WIDTH=200,HEIGHT=300;
private JLabel prompt=new JLabel("Input an integer<=100:");
private IntField intField=new IntField(12,100);
private int userInt;
private String message="hello";
public IntFieldTester(){
add(prompt);
intField.addActionListener(this);
add(intField);
setSize(WIDTH,HEIGHT);
}
public void paintComponent(Graphics g){
g.setColor(getBackground());
g.fillRect(0,0,WIDTH,HEIGHT);
g.setColor(getForeground());
g.drawString(message,10,70);
}
public void actionPerformed(ActionEvent evt){
try{
userInt=intField.getInt();
message="you input"+userInt+"thank you";
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(this,"the input must be an integer.please reenter.");
}catch(IntOutOfRangeException e){
JOptionPane.showMessageDialog(this,e.getMessage());
}finally{
repaint();
}
}
public static void main(String args[]){
JFrame f=new JFrame("inputfield tester");
IntFieldTester panel=new IntFieldTester();
f.getContentPane().add(panel);
f.setSize(panel.WIDTH,panel.HEIGHT);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
}
编译结果如下:
D:\Java\IOE>javac IntFieldTester.java
IntFieldTester.java:7: 找不到符号
符号: 类 IntField
位置: 类 IntFieldTester
private IntField intField=new IntField(12,100);
^
IntFieldTester.java:7: 找不到符号
符号: 类 IntField
位置: 类 IntFieldTester
private IntField intField=new IntField(12,100);
^
IntFieldTester.java:28: 找不到符号
符号: 类 IntOutOfRangeException
位置: 类 IntFieldTester
}catch(IntOutOfRangeException e){
^
3 错误
import java.awt.event.*;
import javax.swing.*;
public class IntFieldTester extends JPanel implements ActionListener{
public static final int WIDTH=200,HEIGHT=300;
private JLabel prompt=new JLabel("Input an integer<=100:");
private IntField intField=new IntField(12,100);
private int userInt;
private String message="hello";
public IntFieldTester(){
add(prompt);
intField.addActionListener(this);
add(intField);
setSize(WIDTH,HEIGHT);
}
public void paintComponent(Graphics g){
g.setColor(getBackground());
g.fillRect(0,0,WIDTH,HEIGHT);
g.setColor(getForeground());
g.drawString(message,10,70);
}
public void actionPerformed(ActionEvent evt){
try{
userInt=intField.getInt();
message="you input"+userInt+"thank you";
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(this,"the input must be an integer.please reenter.");
}catch(IntOutOfRangeException e){
JOptionPane.showMessageDialog(this,e.getMessage());
}finally{
repaint();
}
}
public static void main(String args[]){
JFrame f=new JFrame("inputfield tester");
IntFieldTester panel=new IntFieldTester();
f.getContentPane().add(panel);
f.setSize(panel.WIDTH,panel.HEIGHT);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
}
编译结果如下:
D:\Java\IOE>javac IntFieldTester.java
IntFieldTester.java:7: 找不到符号
符号: 类 IntField
位置: 类 IntFieldTester
private IntField intField=new IntField(12,100);
^
IntFieldTester.java:7: 找不到符号
符号: 类 IntField
位置: 类 IntFieldTester
private IntField intField=new IntField(12,100);
^
IntFieldTester.java:28: 找不到符号
符号: 类 IntOutOfRangeException
位置: 类 IntFieldTester
}catch(IntOutOfRangeException e){
^
3 错误
解决方案 »
- (求解)动态代理类的困惑
- 【转:Java基础知识部分汇总】学JAVA的都进来看一下吧【小熊猫】
- 关于异常的一个问题。请进来看一下。
- 请问:把数据库驱动empressJDBC_cat4.jar打包进client.jar,运行client.jar找不到数据库驱动,为啥?
- JBuiler中的几种类型的Action
- 请问在一个页面表单里 如何用javascript调用exe文件 望高手指点 写出代码
- 调用JNI引起的TOMCAT 关闭
- java的数组是从零开始还是从壹开始的?
- 在一个List中放若干个Map,怎么穷举出来所有的Map的value的组合
- 这个程序那里错了?
- 不继承JFrame 如何使用setDefaultLookAndFeelDecorated(true) 的问题
- java 每次访问sql sever 2000数据库后 需要结束进程么?
不然找不着