c0ntoh

package javaapplication2;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

class AddressDialog extends JDialog {
  JLabel label1 = new JLabel("Nama:");
  JLabel label2 = new JLabel("Alamat:");
  JLabel label3 = new JLabel("Status:");
  JLabel label4 = new JLabel("Bilik:");

  JTextField nama = new JTextField();
  JTextField alamat = new JTextField();
  JTextField status = new JTextField();
  JTextField bilik = new JTextField();

  String[] address = new String[4];

  public AddressDialog(Frame owner, boolean modal) {
    super(owner, modal);
    init();
  }
  private void init() {
    this.setTitle("Percobaan");
    this.setLayout(new GridLayout(4, 2));
    this.add(this.label1);
    this.add(this.nama);
    this.add(this.label2);
    this.add(this.alamat);
    this.add(this.label3);
    this.add(this.status);
    this.add(this.label4);
    this.add(this.bilik);
  }
 public String[] getAddress() {
    address[0] = this.nama.getText();
    address[1] = this.alamat.getText();
    address[2] = this.status.getText();
    address[3] = this.bilik.getText();
    return address;
  }
}
public class Main extends JFrame {
  AddressDialog dialog = new AddressDialog(this, false);

  public Main(String title) {
    super(title);
    init();
  }

  public Main() {
    super();
    init();

  }

  private void init() {
    this.getContentPane().setLayout(new FlowLayout());
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AddressDialog iswan = new AddressDialog(this, false);
    JButton button = new JButton("Silah kan Klik dulu");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
        iswan.setSize(500, 150);
        iswan.setVisible(true);
      }
    });
    this.getContentPane().add(button);
  }

  public static void main(String[] args)
  {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}
===============================================================
package javaapplication8;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.KeyEvent;
import javax.swing.JButton;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    Object username = JOptionPane.showInputDialog(frame, "Siapa Nama Anda....?? ");
    System.out.println(username);
    JFrame halo = new JFrame("ssssssssssssssttt");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("[ ...PERCOBAAN... ]");
    button1.setMnemonic(KeyEvent.VK_B);
    frame.add(button1);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

Diberdayakan oleh Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More