swing(50分)

  • 主题发起人 主题发起人 linuxping
  • 开始时间 开始时间
L

linuxping

Unregistered / Unconfirmed
GUEST, unregistred user!
为何不见LeftPanel上的JTextArea?

import javax.swing.JFrame;
import java.awt.GridLayout;
import cpn.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame();
f.setJMenuBar(new MenuBar());

LeftPanel lp=new LeftPanel();
f.setLayout(new GridLayout(1,2) );
f.getContentPane().add(lp);

f.setSize(700,500);
f.setVisible(true);
}
}

========================
package cpn;
import java.awt.LayoutManager;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTextArea;
import javax.swing.JTree;
import java.awt.Insets;
public class LeftPanel extends JPanel {
public static GridBagLayout gbl;
public LeftPanel() {
this.setLayout(gbl);
GridBagConstraints c=new GridBagConstraints();
c.anchor=GridBagConstraints.NORTH;
c.fill=GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=0;
c.gridheight=1;
c.gridwidth=1;
c.weightx=0;
c.weighty=0;

JTextArea t=new JTextArea("test it");
this.add(t, c);

JTree tree=new JTree();
c.gridy++;
c.insets=new Insets(0,1,0,0);
this.add(tree,c);

}
public LeftPanel(LayoutManager layout) {
super(layout);
// TODO Auto-generated constructor stub
}
public static GridBagLayout getGbl() {
return gbl;
}
public static void setGbl(GridBagLayout gbl) {
LeftPanel.gbl = gbl;
}
}
 
package cpn;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import evn.*;
public class MenuBar extends JMenuBar {
public MenuBar() {
MenuActions ma=new MenuActions();

JMenu m =new JMenu("File");
this.add(m);

JMenuItem item=new JMenuItem("Open");
m.add(item);
item.addActionListener(ma);

item=new JMenuItem("Save");
m.add(item);
item.addActionListener(ma);

item=new JMenuItem("Save As");
m.add(item);
item.addActionListener(ma);


item=new JMenuItem("Close All");
m.add(item);
item.addActionListener(ma);

item=new JMenuItem("Exit");
m.add(item);
item.addActionListener(ma);
}
}

package evn;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MenuActions implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand()=="Open"){

}else
if (e.getActionCommand()=="Save"){

} else
if (e.getActionCommand()=="Save As"){

}else
if (e.getActionCommand()=="Close All"){

}else
if (e.getActionCommand()=="Exit"){

}
}
}
 
???????????????????????????
 
错在哪里?
多谢
 
后退
顶部