import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class MyMDI extends javax.swing.JFrame implements java.awt.event.ActionListener {
public MyMDI() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Erzeugter Quelltext ">
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Test MDI");
getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);
jMenu1.setText("Menu");
jMenuItem1.setText("Fenster aufrufen");
jMenuItem1.addActionListener(this);
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Fenster aufrufen 2");
jMenuItem2.addActionListener(this);
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-887)/2, (screenSize.height-655)/2, 887, 655);
}
// Quelltext zum Weiterleiten von Ereignissen von Komponenten zu Behandlungsmethoden.
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == jMenuItem1) {
MyMDI.this.jMenuItem1ActionPerformed(evt);
}
else if (evt.getSource() == jMenuItem2) {
MyMDI.this.jMenuItem2ActionPerformed(evt);
}
}// </editor-fold>
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
CustomizeInternalFrame iFrame = new CustomizeInternalFrame(jDesktopPane1);
jDesktopPane1.add(iFrame);
iFrame.setVisible(true);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
MyInternalFrame iFrame = new MyInternalFrame(jDesktopPane1);
jDesktopPane1.add(iFrame);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyMDI().setVisible(true);
}
});
}
// Variablendeklaration - nicht modifizieren
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
// Ende der Variablendeklaration
}
class MyInternalFrame extends javax.swing.JInternalFrame {
/** Creates new form MyInternalFrame */
public MyInternalFrame(JDesktopPane desktop) {
initComponents();
JTextField titel = new JTextField("Titel");
JTextField posX= new JTextField("10");
JTextField posY = new JTextField("10");
JTextField width = new JTextField("400");
JTextField height = new JTextField("300");
Object[] msg = {"Titel:", titel, "Pos X:", posX, "Pos Y:", posY, "Länge:", width, "Höhe:", height};
JOptionPane op = new JOptionPane();
if(op.showInternalConfirmDialog(desktop,msg,"Fensterangaben",JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
int x = Integer.parseInt(posX.getText());
int y = Integer.parseInt(posY.getText());
int newWidth = Integer.parseInt(width.getText());
int newHeight = Integer.parseInt(height.getText());
this.setTitle(titel.getText());
this.setBounds(x,y,newWidth,newHeight);
setVisible(true);
} else {
dispose();
}
}
private void initComponents() {
getContentPane().setLayout(null);
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-404)/2, (screenSize.height-313)/2, 404, 313);
}
}
class CustomizeInternalFrame extends javax.swing.JInternalFrame implements java.awt.event.ActionListener {
private JDesktopPane desktop;
public CustomizeInternalFrame(JDesktopPane desktop) {
this.desktop = desktop;
initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
tfTitel = new javax.swing.JTextField();
tfPosX = new javax.swing.JTextField();
tfPosY = new javax.swing.JTextField();
tfWidth = new javax.swing.JTextField();
tfHeight = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setClosable(true);
setTitle("Einstellungen");
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setText("Titel:");
jLabel1.setPreferredSize(new java.awt.Dimension(150, 20));
jLabel2.setText("Position X:");
jLabel2.setPreferredSize(new java.awt.Dimension(150, 20));
jLabel3.setText("Position Y:");
jLabel3.setPreferredSize(new java.awt.Dimension(150, 20));
jLabel4.setText("L\u00e4nge:");
jLabel4.setPreferredSize(new java.awt.Dimension(150, 20));
jLabel5.setText("H\u00f6he:");
jLabel5.setPreferredSize(new java.awt.Dimension(150, 20));
tfTitel.setText("Titel");
tfPosX.setColumns(5);
tfPosX.setText("10");
tfPosY.setColumns(5);
tfPosY.setText("10");
tfWidth.setColumns(5);
tfWidth.setText("400");
tfHeight.setColumns(5);
tfHeight.setText("200");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTitel, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfPosX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfPosY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfTitel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfPosX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfPosY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jButton1.setText("Ok");
jButton1.addActionListener(this);
jButton2.setText("Abbrechen");
jButton2.addActionListener(this);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
setBounds(0, 0, 454, 236);
}
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == jButton1) {
CustomizeInternalFrame.this.jButton1ActionPerformed(evt);
}
else if (evt.getSource() == jButton2) {
CustomizeInternalFrame.this.jButton2ActionPerformed(evt);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JInternalFrame iFrame = new JInternalFrame(); //Das ist dann Dein eigentlicher JInternalFrame
int x = Integer.parseInt(tfPosX.getText());
int y = Integer.parseInt(tfPosY.getText());
int newWidth = Integer.parseInt(tfWidth.getText());
int newHeight = Integer.parseInt(tfHeight.getText());
iFrame.setTitle(tfTitel.getText());
iFrame.setBounds(x,y,newWidth,newHeight);
iFrame.setClosable(true);
iFrame.setVisible(true);
desktop.add(iFrame);
this.dispose();
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField tfHeight;
private javax.swing.JTextField tfPosX;
private javax.swing.JTextField tfPosY;
private javax.swing.JTextField tfTitel;
private javax.swing.JTextField tfWidth;