import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class komputer implements ActionListener
{
JFrame jf;
JTextArea TA;
JComboBox jcb;
Container c;
public komputer()
{
TA=new JTextArea();
TA.setSize(250,75);
TA.setLocation(250,0);
jcb=new JComboBox();
jcb.setSize(250,30);
jcb.setLocation(0,25);
jcb.addActionListener(this);
String c[]={"","CPU","Monitor","Keyboard","Mouse"};
for (int i=0;i<=4;i++){
jcb.addItem(c[i]);
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(jcb))
{
if(jcb.getSelectedItem().equals(""))
{
}else
TA.setText("Anda memilih Item: \n"+jcb.getSelectedItem());
}
}
public void jalan()
{
jf=new JFrame("Komputer");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(null);
c=jf.getContentPane();
c.add(jcb);
c.add(TA);
jf.setSize(500,200);
jf.setVisible(true);
}
public static void main(String[]args)
{
komputer k = new komputer();
k.jalan();
}
}
Print Out

0 comments:
Post a Comment