Study

Event Handling & Sistem Menu [JAVA]

import javax.swing.*;

import java.awt.event.*;

 

class form extends JFrame

{

JLabel lblname=new JLabel(“Name”);

JTextField txtname=new JTextField(30);

JLabel lblgender=new JLabel(“Gender”);

JRadioButton radiomale=new JRadioButton(“Male”);

JRadioButton radiofemale=new JRadioButton(“Female”);

ButtonGroup groupgender=new ButtonGroup();

JLabel lblclass=new JLabel(“Class”);

JCheckBox morning=new JCheckBox(“Morning”);

JCheckBox evening=new JCheckBox(“Evening”);

JCheckBox extension=new JCheckBox(“Extension”);

 

JTextArea txtresult = new JTextArea();

JButton cmd_input=new JButton(“INPUT”);

JButton cmd_exit=new JButton(“EXIT”);

form()

{

setTitle(“Aplikasi GUI”);

setLocation(300,100);

setSize(300,220);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

 

void gui()

{

getContentPane().setLayout(null);

//buat nama

getContentPane().add(lblname);lblname.setBounds(10,10,70,20);

getContentPane().add(txtname); txtname.setBounds(90,10,130,20);

//buat gender

getContentPane().add(lblgender); lblgender.setBounds(10,30,70,20);

getContentPane().add(radiomale); radiomale.setBounds(90,30,60,20);

getContentPane().add(radiofemale); radiofemale.setBounds(160,30,80,20);

groupgender.add(radiomale);

groupgender.add(radiofemale);

//buat kelas

getContentPane().add(lblclass);lblclass.setBounds(10,50,70,20);

getContentPane().add(morning);morning.setBounds(90,50,100,20);

getContentPane().add(evening);evening.setBounds(90,70,100,20);

getContentPane().add(extension);extension.setBounds(90,90,100,20);

//buat tombol

getContentPane().add(cmd_input); cmd_input.setBounds(10,120,70,20);

getContentPane().add(cmd_exit);cmd_exit.setBounds(10,150,70,20);

getContentPane().add(txtresult); txtresult.setBounds(90,120,150,50);

setVisible(true);

}

void perintah()

{

cmd_input.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

//buat name

txtresult.append(txtname.getText()+”\n”);

//buat gender

if(radiomale.isSelected()==true)

{

txtresult.append(radiomale.getText()+”\n”);

}

else

{

txtresult.append(radiofemale.getText()+”\n”);

}

//buat kelas

if(morning.isSelected()==true)

{

txtresult.append(morning.getText()+”\n”);

}

if(evening.isSelected()==true)

{

txtresult.append(evening.getText()+”\n”);

}

if(extension.isSelected()==true)

{

txtresult.append(extension.getText()+”\n”);

}

}

});

cmd_exit.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

});

}

 

public static void main(String[]args)

{

form ds=new form();

ds.gui();

ds.perintah();

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s