InputDialog

Aus Programmers Guide

(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
Zeile 1: Zeile 1:
-
import javax.swing.*;<br>import java.awt.event.*;
+
<source lang="java">
-
 
+
-
public class ShowInputDialog{<br> <br> public ShowInputDialog(){<br> JFrame frame = new JFrame("Input Dialog Box Frame");<br> JButton button = new JButton("Show Input Dialog Box");<br> button.addActionListener(new ActionListener(){<br> public void actionPerformed(ActionEvent ae){<br> String str = JOptionPane.showInputDialog(null, "Enter some text&nbsp;: ", "Roseindia.net", 1);<br> if(str&nbsp;!= null){<br> JOptionPane.showMessageDialog(null, "You entered the text&nbsp;: " + str, "Roseindia.net", 1);<br> }<br> else<br> JOptionPane.showMessageDialog(null, "Abbruch...", "Roseindia.net", 1);<br> }<br> });<br> JPanel panel = new JPanel();<br> panel.add(button);<br> frame.add(panel);<br> frame.setSize(400, 400);<br> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br> frame.setVisible(true);<br> }<br>}<br>  
+
-
 
+
 +
import javax.swing.*;
 +
import java.awt.event.*;
 +
public class ShowInputDialog{
 +
//Konstruktor
 +
public ShowInputDialog(){
 +
  JFrame frame = new JFrame("Input Dialog Box Frame");
 +
  JButton button = new JButton("Show Input Dialog Box");
 +
  button.addActionListener(new ActionListener(){
 +
  public void actionPerformed(ActionEvent ae){
 +
  String str = JOptionPane.showInputDialog(null, "Gib einen Text ein: ", "roy-bohn.de", 1);
 +
  if(str != null){
 +
    JOptionPane.showMessageDialog(null, "Du hast: " + str + " eingegeben", "roy-bohn.de", 1);
 +
  }
 +
  else
 +
  JOptionPane.showMessageDialog(null, "Abbruch...", "roy-bohn.de", 1);
 +
  }
 +
});
 +
JPanel panel = new JPanel();
 +
panel.add(button);
 +
frame.add(panel);
 +
frame.setSize(400, 400);
 +
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 +
frame.setVisible(true);
 +
}
 +
}
 +
</source>
[[Category:Java]]
[[Category:Java]]

Version vom 09:42, 30. Mär. 2010

import javax.swing.*;
import java.awt.event.*;
 
public class ShowInputDialog{
 //Konstruktor
 public ShowInputDialog(){
  JFrame frame = new JFrame("Input Dialog Box Frame");
  JButton button = new JButton("Show Input Dialog Box");
  button.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent ae){
   String str = JOptionPane.showInputDialog(null, "Gib einen Text ein: ", "roy-bohn.de", 1);
   if(str != null){
    JOptionPane.showMessageDialog(null, "Du hast: " + str + " eingegeben", "roy-bohn.de", 1);
   }
   else
   JOptionPane.showMessageDialog(null, "Abbruch...", "roy-bohn.de", 1);
  }
 });
 JPanel panel = new JPanel();
 panel.add(button);
 frame.add(panel);
 frame.setSize(400, 400);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setVisible(true);
 }
}
Persönliche Werkzeuge