JInternalFrame 内部窗口代码问题
publicclassMianFrameextendsJFrame{JDesktopPanedesktopPane=null;//桌面面板InternalFramepln...
public class MianFrame extends JFrame{
JDesktopPane desktopPane=null;//桌面面板
InternalFrame plnFrame=null;//人事管理的内部窗口对象
InternalFrame rlnFrame=null;//账套管理的内部窗口对象
InternalFrame tlnFrame=null;//待遇管理的背部窗体对象
//主方法
public static void main(String[] args) {
// TODO Auto-generated method stub
MianFrame frame=new MianFrame();
frame.setVisible(true);
}
public MianFrame(){
super();
setTitle("管理系统");
setBounds(100,100,570,470);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
desktopPane =new JDesktopPane(); //创建桌面面板对象
desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);//设置内部窗体的拖拽方式(移动时重绘窗体)
getContentPane().add(desktopPane,BorderLayout.CENTER);
//流布局,向左对齐
final JPanel panel=new JPanel();
final FlowLayout flowlayout=new FlowLayout();
flowlayout.setAlignment(FlowLayout.LEFT);
panel.setLayout(flowlayout);
getContentPane().add(panel,BorderLayout.NORTH);
final JButton personelButton=new JButton("人事管理");
personelButton.addActionListener(new BAListener(plnFrame,"人事管理"));
panel.add(personelButton);
final JButton zhangtaoButton=new JButton("账套管理");
zhangtaoButton.addActionListener(new BAListener(rlnFrame,"账号管理"));
panel.add(zhangtaoButton);
final JButton daiyuButton=new JButton("待遇管理");
daiyuButton.addActionListener(new BAListener(tlnFrame,"待遇管理"));
panel.add(daiyuButton);
}
private class BAListener implements ActionListener{
InternalFrame inFrame;
String title;
public BAListener(InternalFrame inFrame,String title){
this.inFrame= inFrame;
this.title=title;
}
下面还有省略了一些代码,篇幅限制不能显示。
public void actionPerformed(ActionEvent e){
if(inFrame== null || inFrame.isClosed()){
//获得桌面面板中的所有内部窗体
JInternalFrame[] allFrame=desktopPane.getAllFrames();
//获得桌面面板中拥有内部窗体的数量
int titleBarHight=30*allFrame.length;
//设定窗体的显示位置
int x=10+titleBarHight;
int y=x;
//设置窗体的大小
int width=250;
int height=180;
//创建制定标题的内部窗口
inFrame=new InternalFrame(title);
。。。。。。
}
private class InternalFrame extends JInternalFrame{
public InternalFrame(String title){
。。。
} 展开
JDesktopPane desktopPane=null;//桌面面板
InternalFrame plnFrame=null;//人事管理的内部窗口对象
InternalFrame rlnFrame=null;//账套管理的内部窗口对象
InternalFrame tlnFrame=null;//待遇管理的背部窗体对象
//主方法
public static void main(String[] args) {
// TODO Auto-generated method stub
MianFrame frame=new MianFrame();
frame.setVisible(true);
}
public MianFrame(){
super();
setTitle("管理系统");
setBounds(100,100,570,470);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
desktopPane =new JDesktopPane(); //创建桌面面板对象
desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);//设置内部窗体的拖拽方式(移动时重绘窗体)
getContentPane().add(desktopPane,BorderLayout.CENTER);
//流布局,向左对齐
final JPanel panel=new JPanel();
final FlowLayout flowlayout=new FlowLayout();
flowlayout.setAlignment(FlowLayout.LEFT);
panel.setLayout(flowlayout);
getContentPane().add(panel,BorderLayout.NORTH);
final JButton personelButton=new JButton("人事管理");
personelButton.addActionListener(new BAListener(plnFrame,"人事管理"));
panel.add(personelButton);
final JButton zhangtaoButton=new JButton("账套管理");
zhangtaoButton.addActionListener(new BAListener(rlnFrame,"账号管理"));
panel.add(zhangtaoButton);
final JButton daiyuButton=new JButton("待遇管理");
daiyuButton.addActionListener(new BAListener(tlnFrame,"待遇管理"));
panel.add(daiyuButton);
}
private class BAListener implements ActionListener{
InternalFrame inFrame;
String title;
public BAListener(InternalFrame inFrame,String title){
this.inFrame= inFrame;
this.title=title;
}
下面还有省略了一些代码,篇幅限制不能显示。
public void actionPerformed(ActionEvent e){
if(inFrame== null || inFrame.isClosed()){
//获得桌面面板中的所有内部窗体
JInternalFrame[] allFrame=desktopPane.getAllFrames();
//获得桌面面板中拥有内部窗体的数量
int titleBarHight=30*allFrame.length;
//设定窗体的显示位置
int x=10+titleBarHight;
int y=x;
//设置窗体的大小
int width=250;
int height=180;
//创建制定标题的内部窗口
inFrame=new InternalFrame(title);
。。。。。。
}
private class InternalFrame extends JInternalFrame{
public InternalFrame(String title){
。。。
} 展开
展开全部
在运行“StudentInformationScan.java”时生成一个窗口,在窗口中我点“修改”按钮时就 ReviseStudentInformation revise=new
ReviseStudentInformation(student);
生成一个新窗口,当我关闭新生成的ReviseStudentInformation窗口时,最开始生成的窗口(StudentInformationScan.java)也被关闭了!但
是我不想关闭最开始的那个窗口?请问该如何解决决?听说将ReviseStudentInformation转化为StudentInformationScan的内嵌窗口,就可以
解决。好像要用到JInternalFrame
package JPanel;
import java.util.Vector;
import java.awt.*;
import javax.swing.*;
import DAO.*;
public class StudentInformationScan extends JFrame implements ActionListener{
private JLabel title;
private JButton revise,delete,addRow;
.......
public StudentInformationScan()
{
p=new JPanel();
revise=new JButton("修改");
revise.setBounds(120, 350, 60, 25);
revise.addActionListener(this);
p.add(revise);
this.setTitle("学生信息浏览");
this.getContentPane().add(p);
this.setSize(510, 500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane getJScrollPane()
{
..........
return scrollpane;
}
public JTable getJTable()
{
........
return table;
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==revise)
{
System.out.println("aaaaaaaaa");
if(table.getSelectedRow()==-1)
{
JOptionPane.showMessageDialog(null, "请选择要修改的行!");
}
else
{
.........
ReviseStudentInformation revise=new ReviseStudentInformation(student);
}
}
}
}
public static void main(String[] args) {
StudentInformationScan student=new StudentInformationScan();
}
}
package JPanel;
import DAO.*;
import javax.swing.*;
import DAO.DBSQLManager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ReviseStudentInformation extends JFrame implements ActionListener{
public ReviseStudentInformation(StudentVO student)
{
.........
revise=new JButton("修改");
revise.setBounds(140, 270, 60, 25);
revise.addActionListener(this);
this.add(revise);
this.setSize(400, 350);
this.setLocation(100, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==revise)
{
........
}
}
}
ReviseStudentInformation(student);
生成一个新窗口,当我关闭新生成的ReviseStudentInformation窗口时,最开始生成的窗口(StudentInformationScan.java)也被关闭了!但
是我不想关闭最开始的那个窗口?请问该如何解决决?听说将ReviseStudentInformation转化为StudentInformationScan的内嵌窗口,就可以
解决。好像要用到JInternalFrame
package JPanel;
import java.util.Vector;
import java.awt.*;
import javax.swing.*;
import DAO.*;
public class StudentInformationScan extends JFrame implements ActionListener{
private JLabel title;
private JButton revise,delete,addRow;
.......
public StudentInformationScan()
{
p=new JPanel();
revise=new JButton("修改");
revise.setBounds(120, 350, 60, 25);
revise.addActionListener(this);
p.add(revise);
this.setTitle("学生信息浏览");
this.getContentPane().add(p);
this.setSize(510, 500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JScrollPane getJScrollPane()
{
..........
return scrollpane;
}
public JTable getJTable()
{
........
return table;
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==revise)
{
System.out.println("aaaaaaaaa");
if(table.getSelectedRow()==-1)
{
JOptionPane.showMessageDialog(null, "请选择要修改的行!");
}
else
{
.........
ReviseStudentInformation revise=new ReviseStudentInformation(student);
}
}
}
}
public static void main(String[] args) {
StudentInformationScan student=new StudentInformationScan();
}
}
package JPanel;
import DAO.*;
import javax.swing.*;
import DAO.DBSQLManager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ReviseStudentInformation extends JFrame implements ActionListener{
public ReviseStudentInformation(StudentVO student)
{
.........
revise=new JButton("修改");
revise.setBounds(140, 270, 60, 25);
revise.addActionListener(this);
this.add(revise);
this.setSize(400, 350);
this.setLocation(100, 100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==revise)
{
........
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询