大家可不可以帮我看看这个类错在哪?

GavinLan 2004-11-01 01:44:23
我找了很久,都不知道为什么那个ActionListener有问题,麻烦哪位好心人帮我找一下,谢谢先!

package mypackage.io;

import java.awt.*;
//import java.lang.*;
import java.awt.Event.*;
//import java.awt.Event;
import javax.swing.*;

/*
Creates request and warn dialog boxes.
*/
public class DialogBox extends JFrame implements ActionListener
{
//instance variables
private JTextField theInput = new JTextField(25);
private JButton ok = new JButton("OK");
private boolean ready = false;

//class variables
private static boolean inputRequested;
public static String request(String requestMessage)
{
//request dialog box with no initial prompt
inputRequested = true;
DialogBox rdb = new DialogBox("Request Dialog Box", requestMessage);
String inputData = rdb.getString();
rdb.dispose();
return inputData;
}

public static String request(String requestMessage, String prompt)
{
//request dialog box with an initial request
inputRequested = true;
DialogBox rdb = new DialogBox("Request Dialog Box",requestMessage, prompt);
rdb.theInput.setCaretPosition(prompt.length());
String inputData = rdb.getString();
rdb.dispose();
return inputData;
}

public static int requestInt(String requestMessage)
{
//request dialog box with no initial prompt; return int
boolean failed = true;
int inputInt = 0;
String inputData = null;
do
{
inputRequested = true;
DialogBox rdb = new DialogBox("Request Dialog Box", requestMessage);
inputData = rdb.getString();
rdb.dispose();
try
{
inputInt = Integer.parseInt(inputData);
failed = false;
}
catch(Exception e)
{
DialogBox.warn("An integer has not been supplied. Try again.");
}
}while(failed);
return inputInt;
}

public static double requestDouble(String requestMessage)
{
//request dialog box with no initial prompt; returns double
boolean failed = true;
double inputNum = 0;
String inputData = null;
do
{
inputRequested = true;
DialogBox rdb = new DialogBox("Request Dialog Box", requestMessage);
inputData = rdb.getString();
rdb.dispose();
try
{
inputNum = Double.valueOf(inputData).doubleValue();
failed = false;
}
catch(Exception e)
{
DialogBox.warn("A number has not been supplied. Try again");
}
}while(failed);
return inputNum;
}

public static void warn(String warnMessage)
{
//warn dialog box
inputRequested = false;
DialogBox wdb = new DialogBox("Message Box", warnMessage);
wdb.waitForData();
wdb.dispose();
}

public DialogBox(String boxType, String boxMessage)
{
//constructor if no initial prompt
super(boxType);
setBounds(410,260,400,100);
Toolkit tk = Toolkit.getDefaultToolkit();
Image im = tk.getImage("F:\\Photo\\other\\美丽得让人窒息027.jpeg");
setIconImage(im);
JPanel p = new JPanel();
p.add(new JLabel(boxMessage));
if(inputRequested)
{
p.add(theInput);
theInput.addActionListener(this);
}
ok.addActionListener(this);
p.add(ok);
setContenPane(p);
setVisible(true);
}

public DialogBox(String boxType, String boxMessage, String prompt)
{
//constructor if there is an initial prompt
super(boxType);
setBounds(410,260,400,100);
Toolkit tk = Toolkit.getDefaultToolkit();
Image im = tk.getImage("F:\\Photo\\other\\美丽得让人窒息027.jpeg");
setIconImage(im);
JPanel p = new JPanel();
p.add(new JLabel(boxMessage));
if(inputRequested)
{
theInput = new JTextField(prompt,25);
theInput.addActionListener(this);
theInput.requestFocus();
p.add(theInput);
}
ok.addActionListener(this);
p.add(ok);
setContentPane(p);
setVisible(true);
}

synchronized public void actionPerformed( ActionEvent e)
{
ready = true;
notifyAll();
}

public boolean dataReady()
{
return ready;
}

public String getString()
{
waitForData(); //Block until data is ready
return theInput.getText();
}

synchronized public void waitForData()
{
if(!ready)
{
try
{
wait();
}
catch(Exception e)
{
//System.out.println("e");
}
}
}
}
...全文
48 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
trumplet 2004-11-01
  • 打赏
  • 举报
回复
象这种错误,用jbuilder不会太难找的,尤其是拼写错误,很好找的。
GavinLan 2004-11-01
  • 打赏
  • 举报
回复
哦,太谢谢了,不知道为什么总是出现一些难以找出来,但是问题又不是很大的问题。^_^
trumplet 2004-11-01
  • 打赏
  • 举报
回复
还有一处拼写错误:
setContenPane(p); 改为 setContentPane(p);
trumplet 2004-11-01
  • 打赏
  • 举报
回复
把 import java.awt.Event.*;
改为:import java.awt.event.*;
发帖
Java

4.9w+

社区成员

Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
帖子事件
创建了帖子
2004-11-01 01:44
社区公告
暂无公告