paintComponent
protected void paintComponent(Graphics g)
Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate). 
If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts. 
这是java的chm的注释~~
-------------------------------------------------

解决方案 »

  1.   

    在这里repaint并没有
    调用paintComponent
    你可以直接把paintComponet重的语句
    写道actionPerform方法中。这样就能完成你要的功能
    repaint语句完成的是调用paint方法
      

  2.   

    public void paintComponent(Graphics g){
            super.paintComonent(g);
            g.drawString(input,50,100);
        }
      

  3.   

    我帮你重新改了一下,不要直接在Frame上画,在面板上画.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class InputDialog2
    {
    public static void main(String[] args)
    {
     InputDialog2Frame f=new InputDialog2Frame();
     f.setVisible(true);
    }
    }
    class InputDialog2Frame extends JFrame 
    {
    InputDialog2Frame()
    {
    super("InputDialog2");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLocation(400,300);
    setSize(300,200);
    ButtonPane p=new ButtonPane();
    Container c=getContentPane();
    c.add(p);
    }
    }class ButtonPane extends JPanel
    {
    String input="";
    ButtonPane()
    {
    JButton click=new JButton("click me");
    add(click);
    click.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    input=JOptionPane.showInputDialog(this,"Please input something");
    repaint();
    }
        
    });
    }
    protected void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    g.drawString(input, 50,100);
    }}