Download presentation
Presentation is loading. Please wait.
Published byAshton McNeil Modified over 11 years ago
1
FH-Hof Dialoge Richard Göbel
2
FH-Hof Inhalt JDialog Vordefinierte Dialoge File Browser
3
FH-Hof Dialogboxen - Unterklasse von JDialog: Attribute public class TestDialog extends JDialog { private JPanel contentPane; private JPanel buttonPanel = new JPanel(); private JButton doneButton = new JButton("Done"); private JButton abortButton = new JButton("Abort"); private JTextField textfield = new JTextField(20);
4
FH-Hof Dialogboxen - Unterklasse von JDialog: Konstruktor public TestDialog (Frame owner, String title) { super(owner, "TestDialog", true); // Modal! contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(textfield); contentPane.add(buttonPanel); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(doneButton); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(abortButton);... pack(); }
5
FH-Hof Dialogboxen - Unterklasse von JDialog: Listener abortButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {... hier die Aktion... setVisible(false); } }); doneButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {... hier die Aktion... setVisible(false); } });
6
FH-Hof Vordefinierte Dialoge - Beispiel JOptionPane pane = new JOptionPane(); String sName = JOptionPane.showInputDialog("Name eingeben:");
7
FH-Hof Vordefinierte Dialoge - weitere Möglichkeiten showConfirmDialog(Component parentComponent, Object message) showInputDialog(Component parentComponent, Object message) showMessageDialog(Component parentComponent, Object message, String title, int messageType) showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
8
FH-Hof File Browser - Darstellung
9
FH-Hof File Browser - Datei laden File file; JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); System.err.println("Loading: " + file.getName()); } else { System.err.println("Open command cancelled"); }
10
FH-Hof File Browser - Datei Speichern File file; JFileChooser fc = new JFileChooser(); int returnVal = fc.showSaveDialog(getContentPane()); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); System.err.println("Saving: " + file.getName()); } else { System.err.println("Open command cancelled"); }
11
FH-Hof JTreeModel Zeichenkette Objekt Zeichenkette Objekt Aufbau eines JTree - Klassen DefaultMutableTreeNode JTree
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.