已经试了2个多小时了,还是不行!
showInputDialog(BianJiQi.contentPane,"请输入您的名字","输入",3);
abc=super.getInputValue().toString();
return abc;要求是弹出一个对话框,里面是有单行文本的,然后用户输入
然后我需要接受用户输入的值
(在JOptionpane类里)查了API 我理解为用getInputValue方法,此方法说此类的一个属性为true时才返回,哪个属性又是protected
所以就继承了JOptionpane类,把哪个属性设置为true,但是还是接受不了!接受到的值是uninitialzedValue

解决方案 »

  1.   

    public static Object showInputDialog(Component parentComponent,
                                         Object message,
                                         String title,
                                         int messageType,
                                         Icon icon,
                                         Object[] selectionValues,
                                         Object initialSelectionValue)
                                  throws HeadlessException
      

  2.   

    不需要那么麻烦,
    JOptionPane.showInputDialog(BianJiQi.contentPane,"请输入您的名字","输入",3) 的返回值就是你的输入值
      

  3.   

    runshine    你太神了,我苦试2小时,你就一句话搞定了!
      

  4.   

    锁定文本框?
    JTextField?  
    setEditable(false)不允许编辑;setEditable(true)允许编辑.不明白你要监听什么事件,鼠标、键盘?还是其它?
      

  5.   

    是一个JMenuItem 点击后  ActionListener
      

  6.   

    还是没弄明白你的意思
    不过写了个你参考下,看看是不是这个意思import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class jh extends Frame implements ActionListener
    {
        static jh frm=new jh();
        
        static TextField tf=new TextField();
        static MenuBar mb=new MenuBar();          
       
        
        static Menu menu1=new Menu("欢迎");
        
        
        static MenuItem mi11=new MenuItem("锁定");
        static MenuItem mi12=new MenuItem("解除");
        
        
        public static void main(String args[])
        {
            BorderLayout br=new BorderLayout();
                
           
            
            mb.add(menu1);
            
            
            menu1.add(mi11);
            menu1.add(mi12);
            
            mi11.addActionListener(frm);
            mi12.addActionListener(frm);
           
            tf.setBounds(20,20,30,15);
            
            
            frm.setSize(400,350);
            frm.setLocation(300,180);
            
            tf.setText("»¶Ó­");
            
            tf.setBounds(5,15,100,15);
            tf.setBackground(Color.PINK);
            
            
            
            frm.setMenuBar(mb);
            frm.add(tf);
            
            frm.setVisible(true);
            
           
            frm.addWindowListener(new WindowAdapter()
            {
                public void windowClosing(WindowEvent e){System.exit(0);}});
            }
      
        
        public  void actionPerformed(ActionEvent e)
        {
            if(e.getSource().equals(mi11))
            {
              tf.setText("锁定了");
              tf.setEditable(false);
            }
            if(e.getSource().equals(mi12))
            {
              tf.setText("解除了");
              tf.setEditable(true);
            }
        }
    }这个演示的就是当你点击相应的MenuItem后,下面的TextField能不能编辑