Annonceindlæg fra Novataris
Vejen til devops med Bavarian Nordic
Bavarian Nordics vækst blev starten på et DevOps-samarbejde med Novataris for hurtigt at kunne tilpasse IT-organisation til forretningen.
7. december 2023
27. november 2002 - 16:27
#2
carsten: Jeg synes ikke helt det virker. Min JOptionPane bliver aldrig Visible.... Frame1: import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Login extends JFrame { public Login() { setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("Frame nr. 1"); setSize(400, 200); setBackground(Color.gray); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = getBounds(); setLocation((screenDim.width - frameDim.width) / 2, (screenDim.height - frameDim.height) / 2); JButton loginKnap = new JButton("Åbn"); loginKnap.setBounds(15, 15, 80, 20); loginKnap.setActionCommand("Test"); loginKnap.addActionListener(actionListener); JPanel panel = new JPanel(); panel.add(loginKnap); getContentPane().add(panel, BorderLayout.CENTER); setVisible(true); } ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String command = actionEvent.getActionCommand(); if (command.equalsIgnoreCase("Test")) { try { System.out.println("test...."); Test2 frame2 = new Test2(); // frame2.setVisible(true); JOptionPane j = new JOptionPane(frame2.getContentPane()); j.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } } }; public static void main(String[] args) { Login login = new Login(); } } Frame2: import javax.swing.*; import java.awt.*; public class Test2 extends JFrame { public Test2() { setTitle("Frame nr. 2"); setSize(350, 150); setBackground(Color.gray); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = getBounds(); setLocation((screenDim.width - frameDim.width) / 2, (screenDim.height - frameDim.height) / 2); JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); } }
28. november 2002 - 09:28
#6
ja måske er det en Jdialog som skal bruge i dette tilfælde. Men jeg er gået lidt i stå. Jeg har Frame1.java og Frame2.java. Når jeg trykker på opret knappen på Frame1, så ønsker jeg at indholdet fra Frame2 skal vises i en JDialog ovenpå Frame1. Man skal så først lukke dialogen, før man igen kan bruge Frame1. Frame1.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Frame1 extends JFrame{ public Frame1() { setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("Frame nr. 1"); setSize(400, 200); setBackground(Color.gray); Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = getBounds(); setLocation((screenDim.width - frameDim.width) / 2, (screenDim.height - frameDim.height) / 2); JButton loginKnap = new JButton("Opret"); loginKnap.setBounds(15, 15, 80, 20); loginKnap.setActionCommand("Test"); loginKnap.addActionListener(actionListener); JPanel panel = new JPanel(); panel.add(loginKnap); getContentPane().add(panel, BorderLayout.CENTER); setVisible(true); } ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String command = actionEvent.getActionCommand(); if (command.equalsIgnoreCase("Test")) { try { //åbn en dialog, og smid den ovenpå denne frame....... } catch (Exception e) { e.printStackTrace(); } } } }; public static void main(String[] args) { Frame1 frame1 = new Frame1(); } } /////////////////////////////// Frame2.java import javax.swing.*; import java.awt.*; public class Frame2 extends JFrame { private JPanel panel3 = null; public Frame2() { panel3 = new JPanel(); getContentPane().add(panel3, BorderLayout.CENTER); setTitle("Opret"); setSize(600, 450); setBackground(Color.gray); createGUI(); /* Center the frame */ Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = getBounds(); setLocation((screenDim.width - frameDim.width) / 2, (screenDim.height - frameDim.height) / 2); setVisible(true); } public void createGUI() { panel3.setLayout(null); JLabel label1 = new JLabel("Firmanavn:"); label1.setBounds(10, 15, 110, 20); panel3.add(label1); JTextField textField1 = new JTextField(); textField1.setBounds(100, 15, 110, 20); panel3.add(textField1); JLabel label2 = new JLabel("CVR Nr:"); label2.setBounds(10, 40, 110, 20); panel3.add(label2); JTextField textField2 = new JTextField(); textField2.setBounds(100, 40, 110, 20); panel3.add(textField2); JLabel label3 = new JLabel("Fornavn:"); label3.setBounds(10, 65, 110, 20); panel3.add(label3); JTextField textField3 = new JTextField(); textField3.setBounds(100, 65, 110, 20); panel3.add(textField3); JLabel label4 = new JLabel("Mellemnavn:"); label4.setBounds(10, 90, 110, 20); panel3.add(label4); JTextField textField4 = new JTextField(); textField4.setBounds(100, 90, 110, 20); panel3.add(textField4); JLabel label5 = new JLabel("Efternavn:"); label5.setBounds(10, 115, 110, 20); panel3.add(label5); JTextField textField5 = new JTextField(); textField5.setBounds(100, 115, 110, 20); panel3.add(textField5); JLabel label6 = new JLabel("Gadenavn:"); label6.setBounds(10, 140, 110, 20); panel3.add(label6); JTextField textField6 = new JTextField(); textField6.setBounds(100, 140, 110, 20); panel3.add(textField6); JLabel label7 = new JLabel("Husnr:"); label7.setBounds(10, 165, 110, 20); panel3.add(label7); JTextField textField7 = new JTextField(); textField7.setBounds(100, 165, 110, 20); panel3.add(textField7); JLabel label8 = new JLabel("Lejlighedsnr:"); label8.setBounds(10, 190, 110, 20); panel3.add(label8); JTextField textField8 = new JTextField(); textField8.setBounds(100, 190, 110, 20); panel3.add(textField8); JLabel label9 = new JLabel("Etagenr:"); label9.setBounds(10, 215, 110, 20); panel3.add(label9); JTextField textField9 = new JTextField(); textField9.setBounds(100, 215, 110, 20); panel3.add(textField9); JLabel label10 = new JLabel("Postnr:"); label10.setBounds(10, 240, 250, 20); panel3.add(label10); JTextField textField10 = new JTextField(); textField10.setBounds(100, 240, 110, 20); panel3.add(textField10); JLabel label11 = new JLabel("By:"); label11.setBounds(10, 265, 110, 20); panel3.add(label11); JTextField textField11 = new JTextField(); textField11.setBounds(100, 265, 110, 20); panel3.add(textField11); JButton GemKnap = new JButton("Gem"); GemKnap.setBounds(500, 15, 90, 20); panel3.add(GemKnap); } } Hvordan?