2012-10-03 43 views
0

我创建了两个类,一个类就像形式另一个类是主类,有jmenu和jinternal框架我想打印来自框架类的输入在jinternal框架,但我不明白我怎么回忆在形式jinternalframe类,请在这方面指导我或任何提示或一些代码或教程,可以帮助我在这里是两个类的代码。而且这两个班都很好。从一个jframe传递值到其他jframe?

JTextArea text; 
    static int openFrameCount = 0; 
    public form(){ 


      super("Insert Form"); 
     Container panel=getContentPane(); 
     JPanel cc = new JPanel(); 
     cc.setLayout(new FlowLayout()); 


     JButton b=new JButton("print"); 
    b.setPreferredSize(new Dimension(140,50)); 
    b.setBounds(1000,500,350,50); 
     cc.add(b); 
     ....................................................... 


     JLabel label1=new JLabel(" Question"+(++openFrameCount)); 

     cc.add(label1); 
     text=new JTextArea(); 
       text.setLineWrap(true); 
     text.setWrapStyleWord(true); 
     text.setPreferredSize(new Dimension(750,50)); 
     text.setBounds(80, 60,750,50); 
     cc.add(text); 
     JLabel symbol=new JLabel("Selection for Option?"); 
     symbol.setBounds(200, 120,1000,100); 
cc.add(symbol); 

    .................................................. 



      JLabel op4=new JLabel("4th Option?"); 
      JTextArea otext4=new JTextArea(); 
      otext4.setLineWrap(true); 
     otext4.setWrapStyleWord(true); 
     otext4.setPreferredSize(new Dimension(750,50)); 
     otext4.setBounds(10, 40,700,30); 
      cc.add(op4) ; 
      cc.add(otext4) ; 






      cc.revalidate(); 
validate(); 

    ............................................................ 

     } 

    @Override 
    public void actionPerformed(ActionEvent ae) { 
    if (e.getSource() == b1){ 

    } 

} 

} 和第二类的JInternalFrame的是

public class Desktop1 extends JFrame 
           implements ActionListener { 
    Desktop p=new Desktop(); 
    JDesktopPane desktop; 

static int openFrameCount = 0; 
    public Desktop1() { 
     super("InternalFrameDemo"); 

     //Make the big window be indented 50 pixels from each edge 
     //of the screen. 
     int inset = 50; 
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
     setBounds(inset, inset, 
        screenSize.width - inset*2, 
        screenSize.height - inset*2); 

     //Set up the GUI. 
     desktop = new JDesktopPane(); //a specialized layered pane 

     createFrame(); //create first "window" 
     setContentPane(desktop); 
     setJMenuBar(createMenuBar()); 

     //Make dragging a little faster but perhaps uglier. 
     desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); 
    } 

    protected JMenuBar createMenuBar() { 
     JMenuBar menuBar = new JMenuBar(); 

     //Set up the lone menu. 


     ................................................. 



     return menuBar; 
    } 

    //React to menu selections. 
    public void actionPerformed(ActionEvent e) { 
     if ("new".equals(e.getActionCommand())) { //new 
      createFrame(); 
     } 

     ............................................ 
     } 
    } 


    class MyInternalFrame extends JInternalFrame { 

     static final int xPosition = 30, yPosition = 30; 
     public MyInternalFrame() { 
      super("IFrame #" + (++openFrameCount), true, // resizable 
        true, // closable 
        true, // maximizable 
        true);// iconifiable 
      setSize(700, 700); 
      // Set the window's location. 
      setLocation(xPosition * openFrameCount, yPosition 
        * openFrameCount); 
     } 
    } 
    //Create a new internal frame. 
    protected void createFrame() { 
     Desktop1.MyInternalFrame frame = new Desktop1.MyInternalFrame(); 


     JPanel panel=new JPanel();//to add scrollbar in jinternalpane insert jpanel 
     panel.setBackground(Color.white);//set background color of jinternal frame 
     JScrollPane scrollBar=new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
     frame.add(scrollBar); 

     frame.setVisible(true); 


     desktop.add(frame); 
     try { 
      frame.setSelected(true); 
      frame.setMaximum(true); 
     } catch (java.beans.PropertyVetoException e) {} 
    } 
    public static void main(String[] args) { 
     Desktop1 d=new Desktop1(); 
     d.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
     d.setVisible(true); 

} 
} 

我想知道有关进来的这部分代码的工作提示形式的值传递给内部框架当我点击在打印按钮

public void actionPerformed(ActionEvent ae) { 
     if (e.getSource() == b1){ 

     } 

    } 
} 

回答

0

我猜你想要一些文本传递给您的InternalFrame类从主要形式的按钮点击。 修改您createFrame()方法接受一个字符串值 e.g-

protected void createFrame(String value){ 
//..your code  
} 

,当你打电话给你InternalFrame类,此值传递给它的构造。例如

Desktop1.MyInternalFrame frame = new Desktop1.MyInternalFrame(value); 

参数化构造函数将解决您的问题。修改InternalFrame构造 e.g-

public MyInternalFrame(String value){ 
//..use this value  
} 
+0

能否请您解释一下更???? – janat

+0

我编辑了我的答案。 – Mohsin

0

只是调用构造函数并传递价值

ClassName(parameter) 
相关问题