Thursday, June 6, 2013

Bikin Program Nama Dengan GUI

Source Code :

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Container;
import java.awt.FlowLayout;

public class Jawaban1_GUI extends JFrame implements ActionListener
{
private JButton btnNim;
private JButton btnNama;
private JButton btnJurusan;

    public Jawaban1_GUI() 
    {
    setTitle("RESPONSI GUI");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setLocationRelativeTo(null);
    setResizable(false);
   
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
   
    btnNim = new JButton("Nomor Mahasiswa");
    btnNama = new JButton("Nama");
    btnJurusan = new JButton("Jurusan dan Kelas");
   
    pane.add(btnNim);
    pane.add(btnNama);
    pane.add(btnJurusan);
   
    btnNim.addActionListener(this);
    btnNama.addActionListener(this);
    btnJurusan.addActionListener(this);
   
    pack();
    }
    
    public void actionPerformed(ActionEvent evt)
    {
    Object src = evt.getSource();
    JOptionPane.showMessageDialog(null, src == btnNim ? "12.11.6156" : src == btnNama ? " JAKA " : 
    "TEKNIK INFORMATIKA KELAS TI - 06");
    }
    
    public static void main(String [] args)
    {
    new Jawaban1_GUI().setVisible(!false && 1 < 5); // -> true, lolololol :p
    }
}

Outputnya :


0 comments:

Post a Comment