我的程序有3个按钮,每一个按钮都要处理数据库中的不同的数据,我想在处理数据的时候能有提示,比如弹出一个对话框或窗口或其他的东西,上面有文字,说明现在正在进行数据处理,等数据库中的数据处理完后,这个提示就自动消失。我应该怎么作?最好能给出代码。谢谢!
解决方案 »
- 跪求:java.sql.SQLException: OALL8 处于不一致状态,违反协议,如何解决
- 关于 imageIO.read(File f) 的问题
- 无法访问StringBuffer
- 个人见解,欢迎拍砖:eqluals和"=="的区别
- 简单问题,如何用java得到一个目录下的所有文件名称??高分
- 关于java的正则表达式中.和&&
- java编程出现空指针异常
- 我在事务处理中运用到两个statement方法的疑问?急救
- [讨论]如何开发一套数据库操作APIs
- 为什么像这样的地址../Lib/test/test.htm,转换成绝对地址不正确??
- 关于图像的问题
- 一个bufferedImage的问题
import java.awt.*;
import java.awt.event.*;public class T1113 extends JFrame{
JButton b = new JButton("execute");
Processing p;
public T1113(){
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
p = new Processing(T1113.this);
p.setVisible(true);
process();
p.setVisible(false);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,300);
this.setVisible(true);
}
public void process(){
try{
System.out.println("processing");
Thread.sleep(3000);
System.out.println("processed");
}catch(InterruptedException ie){
ie.printStackTrace();
}
}
public static void main(String args[]){
new T1113();
}
}
class Processing extends JDialog{
public Processing(JFrame parent){
super(parent,"processing...",false);
this.setSize(200,80);
}
}
import java.awt.*;
import java.awt.event.*;public class Test extends JFrame implements ActionListener,Runnable
{
private JButton btnGood = new JButton("计算");
private JLabel jLabel=new JLabel("");
private Thread thread;
private JPanel contentPane;
private JPanel panel = new JPanel(); public Test()
{
thread=new Thread(this);
contentPane = (JPanel)this.getContentPane();
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.add(btnGood);
panel.add(jLabel);
btnGood.addActionListener(this);
contentPane.add(panel);
this.setSize(270,250);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
this.setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2);
this.setVisible(true);
} public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == btnGood)
{
thread.start();
for(int i=0;i<1000;i++)
for(int j=0;j<1000;j++)
{} try{
thread.sleep(100);
}catch(InterruptedException e){}
thread=null;
}
} public void run()
{
while(thread!=null)
{
if(jLabel.getText()==""||jLabel.getText().equals("")) jLabel.setText("系统正在进行信息处理,请等待!");
}
jLabel.setText("");
} public static void main(String args[]){
new Test();
}
}z这个程序有问题,谁改一下?
import java.awt.*;
import java.awt.event.*;public class Test2 extends JFrame implements ActionListener
{
private JButton btnGood = new JButton("计算");
private JLabel jLabel=new JLabel("系统正在进行信息处理,请等待!");
private JPanel contentPane;
private JPanel panel = new JPanel(); public Test2()
{
contentPane = (JPanel)this.getContentPane();
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.add(btnGood);
panel.add(jLabel);
jLabel.setVisible(false);
btnGood.addActionListener(this);
contentPane.add(panel);
this.setSize(270,250);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
this.setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2);
this.setVisible(true);
} public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == btnGood)
{
jLabel.setVisible(true);
System.out.println("start");
try{
Thread.sleep(3000);
}catch(InterruptedException ie){
ie.printStackTrace();
}
jLabel.updateUI(); for(int i=0;i<100000;i++)
for(int j=0;j<100000;j++)
{}
System.out.println("end");
jLabel.setVisible(false);
}
} public static void main(String args[]){
new Test2();
}
}这个也不行,swing控件好像反应迟钝
import java.awt.*;
import java.awt.event.*;public class MainClass extends JFrame implements ActionListener,Runnable
{
boolean flag = false;
HintJDialog hintJDialog=new HintJDialog(this);
static Thread t;
static Thread t2;
private JButton btnGood = new JButton("计算");
private JPanel contentPane;
private JPanel panel = new JPanel(); public MainClass()
{
//t = new Thread(this, "run");
//t2 = new Thread(this, "wait");
contentPane = (JPanel)this.getContentPane();
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.add(btnGood);
btnGood.addActionListener(this);
contentPane.add(panel);
this.setSize(270,250);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
this.setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2);
this.setVisible(true);
} public static void main(String[] args)
{
// TODO Auto-generated method stub
MainClass m = new MainClass(); } public void run()
{ if (Thread.currentThread().getName().startsWith("r"))
{
calculate();
}
else
{
waiting();
}
} public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == btnGood)
{
t = new Thread(this, "run");
t2 = new Thread(this, "wait");
//if(!t.isAlive()) t.start();
//if(!t2.isAlive()) t2.start();
t.start();
t2.start();
}
} protected synchronized void calculate()
{
int i = 0;
try
{
hintJDialog.setVisible(true);
while (i < 100)
{
Thread.sleep(30);
System.out.println("计算到" + i);
i++;
}
flag = true;
this.notifyAll();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
protected synchronized void waiting()
{
try
{
while (!flag)
{
wait();
}
hintJDialog.setVisible(false);
System.out.println("执行完毕......");
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
import java.awt.*;public class HintJDialog extends JDialog
{
private ImageIcon imageIcon1=new ImageIcon("gif\\1.gif");
private ImageIcon imageIcon2=new ImageIcon("gif\\2.gif");
private ImageIcon imageIcon3=new ImageIcon("gif\\3.gif");
private ImageIcon imageIcon4=new ImageIcon("gif\\4.gif");
private JLabel jLabel;
public HintJDialog(JFrame parent)
{
super(parent,"系统正在进行信息处理,请等待!",false);
this.getContentPane().setLayout(new GridLayout(2,1,0,0));
jLabel=new JLabel(imageIcon1);
this.getContentPane().add(jLabel);
jLabel=new JLabel(imageIcon2);
this.getContentPane().add(jLabel);
jLabel=new JLabel(imageIcon3);
this.getContentPane().add(jLabel);
jLabel=new JLabel(imageIcon4);
this.getContentPane().add(jLabel);
this.setSize(270,250);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
this.setLocation((screenSize.width - frameSize.width)/2,(screenSize.height - frameSize.height)/2);
}
}