私はEclipse用のビジュアルスイングプラグインを使用しています - これが問題です。ボタンをクリックすると、ダイアログ(または他のjFormですが、アプリケーションで使用する必要があるのは1つのjfromのみであると読みました)が表示され、最初のものは非表示になりますが、これは問題ではありません。しかし、2番目のフォームでは、ボタンをクリックすると同じことが起こる必要があり、最初のフォームを表示し、2番目のフォームを破棄する必要があります。これがコードです(この視覚的なスイングを回避する方法が見つからないため、おそらくあまりソートされていません)
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
import org.dyno.visual.swing.layouts.Trailing;
//VS4E -- DO NOT REMOVE THIS LINE!
public class Intervencije extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jPanel1;
private JButton btnObjekat;
private JButton btnEkipa;
private JButton btnIzlaz;
private JLabel jLabel0;
private JPanel jPanel0;
private JTextField txtBrojIntervencije;
private JButton btnUcitaj;
private JLabel jLabel3;
private JPanel jPanel2;
private JLabel jLabel1;
private JLabel jLabel2;
private JTextField txtDatum;
private JTextField txtBroj;
private JTextArea txtOpisi;
private JScrollPane jScrollPane0;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public Intervencije() {
this.pack();
this.setDefaultCloseOperation(Intervencije.EXIT_ON_CLOSE);
this.setVisible(true);
//this.setLocationRelativeTo(null);
initComponents();
}
private void initComponents() {
setTitle("Intervencije");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setLayout(new GroupLayout());
add(getJPanel2(), new Constraints(new Leading(17, 422, 10, 10), new Leading(226, 71, 10, 10)));
add(getJPanel0(), new Constraints(new Leading(12, 189, 12, 12), new Leading(18, 100, 10, 10)));
add(getJPanel1(), new Constraints(new Leading(205, 227, 12, 12), new Leading(15, 202, 10, 10)));
setSize(454, 334);
}
private JTextArea getTxtOpisi() {
if (txtOpisi == null) {
txtOpisi = new JTextArea();
txtOpisi.setEditable(false);
txtOpisi.setText("txtOpisi");
txtOpisi.setMinimumSize(new Dimension(80, 16));
txtOpisi.setPreferredSize(new Dimension(80, 16));
}
return txtOpisi;
}
private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setViewportView(getJTextArea0());
}
return jScrollPane0;
}
private JTextArea getJTextArea0() {
if (txtOpisi == null) {
txtOpisi = new JTextArea();
}
return txtOpisi;
}
private JTextField getJTextField2() {
if (txtBroj == null) {
txtBroj = new JTextField();
}
return txtBroj;
}
private JTextField getJTextField1() {
if (txtDatum == null) {
txtDatum = new JTextField();
}
return txtDatum;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Opis");
}
return jLabel2;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("Datum i vreme");
}
return jLabel1;
}
private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(new GroupLayout());
jPanel2.add(getJButton0(), new Constraints(new Leading(278, 10, 10), new Leading(35, 10, 10)));
jPanel2.add(getJButton1(), new Constraints(new Leading(151, 10, 10), new Leading(35, 12, 12)));
jPanel2.add(getJButton2(), new Constraints(new Leading(23, 10, 10), new Leading(35, 12, 12)));
jPanel2.add(getJLabel3(), new Constraints(new Leading(184, 173, 10, 10), new Leading(9, 10, 10)));
}
return jPanel2;
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("Vise informacija o");
}
return jLabel3;
}
private JButton getJButton3() {
if (btnUcitaj == null) {
btnUcitaj = new JButton();
btnUcitaj.setText("Ucitaj");
}
return btnUcitaj;
}
private JPanel getJPanel0() {
if (jPanel0 == null) {
jPanel0 = new JPanel();
jPanel0.setLayout(new GroupLayout());
jPanel0.add(getJLabel0(), new Constraints(new Trailing(12, 12, 12), new Leading(3, 19, 10, 10)));
jPanel0.add(getJButton3(), new Constraints(new Leading(21, 10, 10), new Leading(66, 12, 12)));
jPanel0.add(getJTextField2(), new Constraints(new Leading(15, 72, 12, 12), new Leading(28, 12, 12)));
}
return jPanel0;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("Unesite redni broj intervencije");
}
return jLabel0;
}
private JButton getJButton2() {
if (btnIzlaz == null) {
btnIzlaz = new JButton();
btnIzlaz.setText("Izlaz");
btnIzlaz.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
btnIzlazMouseMouseClicked(event);
}
});
}
return btnIzlaz;
}
private JButton getJButton1() {
if (btnEkipa == null) {
btnEkipa = new JButton();
btnEkipa.setText("Ekipi");
btnEkipa.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
btnEkipaMouseMouseClicked(event);
}
});
}
return btnEkipa;
}
private JButton getJButton0() {
if (btnObjekat == null) {
btnObjekat = new JButton();
btnObjekat.setText("Objektu");
}
return btnObjekat;
}
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setLayout(new GroupLayout());
jPanel1.add(getJLabel1(), new Constraints(new Leading(4, 135, 10, 10), new Leading(2, 29, 10, 10)));
jPanel1.add(getJLabel2(), new Constraints(new Leading(13, 12, 12), new Leading(69, 57, 115)));
jPanel1.add(getJTextField1(), new Constraints(new Leading(8, 105, 12, 12), new Leading(31, 12, 12)));
jPanel1.add(getJScrollPane0(), new Constraints(new Bilateral(12, 12, 22), new Bilateral(99, 12, 22)));
}
return jPanel1;
}
public static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
+ " on this platform:" + e.getMessage());
}
}
/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
private void btnIzlazMouseMouseClicked(MouseEvent event) {
this.dispose();
}
public void btnEkipaMouseMouseClicked(MouseEvent event) {
this.setVisible(false);
Objekat o = new Objekat();
o.setVisible(true);
}
}
ここで objekat o は、JFrame または JDialog を拡張するクラスです。
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class Objekat extends JDialog {
private static final long serialVersionUID = 1L;
private JButton jButton0;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public Objekat(JFrame parent) {
super(parent);
initComponents();
}
public Objekat(Dialog parent, String title, boolean modal,
GraphicsConfiguration arg) {
super(parent, title, modal, arg);
initComponents();
}
public Objekat(Dialog parent, String title, boolean modal) {
super(parent, title, modal);
initComponents();
}
public Objekat(Dialog parent, String title) {
super(parent, title);
initComponents();
}
public Objekat(Window parent, String title, ModalityType modalityType,
GraphicsConfiguration arg) {
super(parent, title, modalityType, arg);
initComponents();
}
public Objekat(Window parent, String title, ModalityType modalityType) {
super(parent, title, modalityType);
initComponents();
}
public Objekat(Window parent, String title) {
super(parent, title);
initComponents();
}
public Objekat(Window parent, ModalityType modalityType) {
super(parent, modalityType);
initComponents();
}
public Objekat(Frame parent, String title) {
super(parent, title);
initComponents();
}
public Objekat(Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
public Objekat(Frame parent) {
super(parent);
initComponents();
}
public Objekat() {
initComponents();
}
public Objekat(Dialog parent, boolean modal) {
super(parent, modal);
initComponents();
}
public Objekat(Dialog parent) {
super(parent);
initComponents();
}
public Objekat(Frame parent, String title, boolean modal,
GraphicsConfiguration arg) {
super(parent, title, modal, arg);
initComponents();
}
public Objekat(Frame parent, String title, boolean modal) {
super(parent, title, modal);
initComponents();
}
private void initComponents() {
setFont(new Font("Dialog", Font.PLAIN, 12));
setBackground(Color.white);
setForeground(Color.black);
setLayout(new GroupLayout());
add(getJButton0(), new Constraints(new Leading(237, 10, 10), new Leading(81, 10, 10)));
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
mouseMouseClicked(event);
}
});
setSize(428, 240);
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("jButton0");
}
return jButton0;
}
private static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
+ " on this platform:" + e.getMessage());
}
}
/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
// public static void main(String[] args) {
// installLnF();
// SwingUtilities.invokeLater(new Runnable() {
// public void run() {
// Objekat dialog = new Objekat();
// dialog.setDefaultCloseOperation(Objekat.DISPOSE_ON_CLOSE);
// dialog.setTitle("Objekat");
// dialog.setLocationRelativeTo(null);
// dialog.getContentPane().setPreferredSize(dialog.getSize());
// dialog.pack();
// dialog.setVisible(true);
// }
// });
private void mouseMouseClicked(MouseEvent event) {
//this.getParent().setVisible(true);
this.setVisible(false);
}
}
主要
public class main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Intervencije d = new Intervencije();
d.setLocationRelativeTo(null);
//d.setVisible(true);
//d.installLnF();
}