在拆分面板Java中调用JPanel

时间:2012-03-15 15:45:37

标签: java swing jpanel jsplitpane

嗨,我的代码遇到了问题。当我点击按钮和Keypressed(回车)时,我无法在Minimize类的splitpane中调用或显示我的JPanel(TruthTable)。问题在于类Minimize

*更新:我已经解决了有关绘制面板的问题我的下一个问题是当我调用构造函数时,面板中的文本应该更新。我还更改了setText以追加'因为他们说JPanel不支持setText。我已经使用过,验证,重绘方法但没有运气更新textArea。

enter image description here

继承我的最小化代码:

package splashdemo;

public class Minimize extends JPanel implements ClipboardOwner
{

      simButton.addActionListener(new ActionListener()
      { public void actionPerformed(ActionEvent ae)
        {
            LogicGates lg= new LogicGates();
            lg.geth();
            sim s=new sim();
            s.InputExp(lg.g,lg.g1);
            s.menu();
            s.setSize(700,700);
            s.setVisible(false);
            Frame f = new Frame();
            Panel panel = new Panel();
            f.add(BorderLayout.SOUTH, panel);
            f.add(BorderLayout.CENTER, new sim());
            f.add(BorderLayout.SOUTH, panel);
            f.setSize(580, 500);
            panel.add(s.button);
            f.show();
            f.setVisible(false);


JOptionPane.showMessageDialog(null, b);
ex=b;
cAppend();
JOptionPane.showMessageDialog(null, ex1);
InToPost(ex1);
        foutput= doTrans();
        JOptionPane.showMessageDialog(null, foutput);

             TruthTable_1 kl = new TruthTable_1(foutput);

            Minimize mi = new Minimize();
             s.InputExp(lg.g,lg.g1);
             s.menu();
            lg.gatessplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mi, lg.p1);

//here's the splitpane where I should display the TruthTable_1 panel but it doesn't diplay
          lg.p1.add(lg.gatessplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, s,kl));
            lg.gatessplit.setOneTouchExpandable(true);
            lg.gatessplit.setDividerLocation(250);
            lg.gatessplit.setPreferredSize(new Dimension(900, 500));
            lg.createAndShowGUI();


        }});


    }

继承我的代码TruthTable_1:constructors

public TruthTable_1() {
      super();
tableArea.append("This is a Test");
      //setBackground(Color.black);
    createg();

      setVisible(true);
    }
        public void createg(){
            setLayout(new BorderLayout());
        line= 0;
        truth= 'T';
        fallacy= 'F';
        final JPanel top= new JPanel();
        input= new TextField(35);
        TFCheck= new Checkbox("Select for \"1/0\" (default\"T/F\")");
        check= new JButton("Check");
        check.addActionListener(this);

        top.add(input);
        top.add(TFCheck);
        top.add(check);
                top.setVisible(false);
        tableArea= new JTextArea(16, 40);
        tableArea.setEditable(false);
        tableArea.setFont(new Font("Lucida Console", Font.PLAIN, 14));
        // all letters are the same width in this font

        go= new JButton("Do it to it!");
        go.addActionListener(this);
        input.addActionListener(this);
                go.setVisible(false);
        add(top, BorderLayout.NORTH);
        scrolls= new JScrollPane(tableArea);// add scroll buttons to the area
        add(scrolls, BorderLayout.CENTER);
        add(go, BorderLayout.SOUTH);
        setSize(535, 500);
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocation(100, 100);
        }
    public TruthTable_1(String f){
            createg();

                 tableArea.append(run(f));

    }

0 个答案:

没有答案