一段代码,目的是在帧内做一按钮,点击按钮,就进行后台的数据库操作(经测试,没问题),由于后台数据库的操作时间较长(大概10分钟),所以我打算在点击按钮的同时在帧内能出现一段文字“入库中......”。代码片断如下:
class ButtonPanel extends JPanel implements ActionListener { public ButtonPanel() {
button = new JButton("入库");
add(button);
button.addActionListener(this);
} public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
//PrintOut printout=new PrintOut();
if (source == button) { 
/***************************************************************/
PrintOut printout = new PrintOut();
Graphics g=null;
printout.paintComponent(g);
/***************************************************************/
InsertDb indb = new InsertDb();
indb.insertDb();
}
}
private JButton button;
}class ButtonFrame extends JFrame {
public ButtonFrame() {
Toolkit kit = Toolkit.getDefaultToolkit();
setTitle("入库");
setSize(300, 200);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());

Image img = kit.getImage("biao.gif");
setIconImage(img);
}
}class PrintOut extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("入库中....", MESSAGE_X, MESSAGE_Y);
} public static final int MESSAGE_X = 85; public static final int MESSAGE_Y = 100;
}说明:问题就出在下面的代码:
        /***************************************************************/
PrintOut printout = new PrintOut();
Graphics g=null;
printout.paintComponent(g); /***************************************************************/调用PrintOut类的paintComponent方法出错。原因可能是Graphics类型的g不能为空,可是怎么改呢?让g等于什么就可以了呢?
请赐教!!!!!!