Вы находитесь на странице: 1из 5

/* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package uts; import import import import import java.awt.*; java.awt.event.ActionEvent; java.awt.event.ActionListener; java.awt.event.WindowAdapter; java.awt.event.WindowEvent;

/** * * @author aci */ public class Uts { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here lebarJendela = 800; tinggiJendela = 300; lebarPanel = lebarJendela/5; tinggiPanel = tinggiJendela/2; lebarTombol = 100; tinggiTombol = 30; awalTombX = (lebarPanel-lebarTombol)/2; awalTombY = (tinggiPanel-tinggiTombol)/2;

int int int int int int int int

Dimension Layar = Toolkit. getDefaultToolkit(). getScreenSize(); int lebarLayar = Layar.width; int tinggiLayar = Layar.height; int awalJendX = (lebarLayar-lebarJendela)/2; int awalJendY = (tinggiLayar-tinggiJendela)/2; final Frame f = new Frame("UTS"); f.setTitle("UJIAN TS"); f.setLayout(null); f.setLocation(awalJendX,awalJendY); f.setSize(lebarJendela,tinggiJendela); f.setVisible(true); final Panel atas1 = new Panel(); atas1.setSize(lebarPanel,tinggiPanel); atas1.setLocation(0,0); atas1.setBackground(Color.RED); f.add(atas1); final Panel atas2 =new Panel(); atas2.setSize(lebarPanel,tinggiPanel); atas2.setLocation(lebarPanel,0); atas2.setBackground(Color.yellow); f.add(atas2);

final Panel atas3 =new Panel(); atas3.setSize(lebarPanel,tinggiPanel); atas3.setLocation(2*lebarPanel,0); atas3.setBackground(Color.green); f.add(atas3); Panel atas4 =new Panel(); atas4.setSize(2*lebarPanel,tinggiPanel); atas4.setLocation(3*lebarPanel,0); atas4.setBackground(Color.black); f.add(atas4); final Button tombolatas1 = new Button(); tombolatas1.setSize(lebarTombol,tinggiTombol); tombolatas1.setLocation(awalTombX,awalTombY); tombolatas1.setLabel("PUTAR"); atas1.add(tombolatas1); atas1.setLayout(null); final Button tombolatas2 = new Button(); tombolatas2.setSize(lebarTombol,tinggiTombol); tombolatas2.setLocation(awalTombX,awalTombY); tombolatas2.setLabel("PUTAR"); atas2.add(tombolatas2); atas2.setLayout(null); final Button tombolatas3 = new Button(); tombolatas3.setSize(lebarTombol,tinggiTombol); tombolatas3.setLocation(awalTombX,awalTombY); tombolatas3.setLabel("PUTAR"); atas3.add(tombolatas3); atas3.setLayout(null); Panel bawah1 = new Panel(); bawah1.setSize(2*lebarPanel,tinggiPanel); bawah1.setLocation(0,tinggiPanel); bawah1.setBackground(Color.black); f.add(bawah1); final Panel bawah2 =new Panel(); bawah2.setSize(lebarPanel,tinggiPanel); bawah2.setLocation(2*lebarPanel,tinggiPanel); bawah2.setBackground(Color.blue); f.add(bawah2); final Panel bawah3 =new Panel(); bawah3.setSize(lebarPanel,tinggiPanel); bawah3.setLocation(3*lebarPanel,tinggiPanel); bawah3.setBackground(Color.magenta); f.add(bawah3); final Panel bawah4 =new Panel(); bawah4.setSize(lebarPanel,tinggiPanel); bawah4.setLocation(4*lebarPanel,tinggiPanel); bawah4.setBackground(Color.white); f.add(bawah4); final Button tombolbawah2 = new Button(); tombolbawah2.setSize(lebarTombol,tinggiTombol); tombolbawah2.setLocation(awalTombX,awalTombY);

tombolbawah2.setLabel("PUTAR"); bawah2.add(tombolbawah2); bawah2.setLayout(null); final Button tombolbawah3 = new Button(); tombolbawah3.setSize(lebarTombol,tinggiTombol); tombolbawah3.setLocation(awalTombX,awalTombY); tombolbawah3.setLabel("PUTAR"); bawah3.add(tombolbawah3); bawah3.setLayout(null); final Button tombolbawah4 = new Button(); tombolbawah4.setSize(lebarTombol,tinggiTombol); tombolbawah4.setLocation(awalTombX,awalTombY); tombolbawah4.setLabel("PUTAR"); bawah4.add(tombolbawah4); bawah4.setLayout(null); tombolatas1.setVisible(true); tombolatas2.setVisible(false); tombolatas3.setVisible(false); tombolbawah2.setVisible(false); tombolbawah3.setVisible(false); tombolbawah4.setVisible(false);

//

tombolatas1.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ f.setTitle("atas1 action"); atas1.setBackground(Color.white); atas2.setBackground(Color.red); atas3.setBackground(Color.yellow); bawah2.setBackground(Color.green); bawah3.setBackground(Color.blue); bawah4.setBackground(Color.magenta); atas4.setBackground(Color.blue); tombolatas1.setVisible(false); tombolatas2.setVisible(true); tombolatas3.setVisible(false); tombolbawah2.setVisible(false); tombolbawah3.setVisible(false); tombolbawah4.setVisible(false); } } ); tombolatas2.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ f.setTitle("atas 2 action"); atas1.setBackground(Color.magenta); atas2.setBackground(Color.white); atas3.setBackground(Color.red); bawah2.setBackground(Color.yellow); bawah3.setBackground(Color.green); bawah4.setBackground(Color.blue);

//

atas4.setBackground(Color.blue); tombolatas1.setVisible(false); tombolatas2.setVisible(false); tombolatas3.setVisible(true); tombolbawah2.setVisible(false); tombolbawah3.setVisible(false); tombolbawah4.setVisible(false); } } ); tombolatas3.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ f.setTitle("atas 3 action"); atas1.setBackground(Color.blue); atas2.setBackground(Color.magenta); atas3.setBackground(Color.white); bawah2.setBackground(Color.red); bawah3.setBackground(Color.yellow); bawah4.setBackground(Color.green); atas4.setBackground(Color.blue); tombolatas1.setVisible(false); tombolatas2.setVisible(false); tombolatas3.setVisible(false); tombolbawah2.setVisible(true); tombolbawah3.setVisible(false); tombolbawah4.setVisible(false); } } ); tombolbawah2.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ f.setTitle("bawah 2 action"); atas1.setBackground(Color.green); atas2.setBackground(Color.blue); atas3.setBackground(Color.magenta); bawah2.setBackground(Color.white); bawah3.setBackground(Color.red); bawah4.setBackground(Color.yellow); atas4.setBackground(Color.blue); tombolatas1.setVisible(false); tombolatas2.setVisible(false); tombolatas3.setVisible(false); tombolbawah2.setVisible(false); tombolbawah3.setVisible(true); tombolbawah4.setVisible(false); } } ); tombolbawah3.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){

//

//

//

f.setTitle("bawah 3 action"); atas1.setBackground(Color.yellow); atas2.setBackground(Color.green); atas3.setBackground(Color.blue); bawah2.setBackground(Color.magenta); bawah3.setBackground(Color.white); bawah4.setBackground(Color.red); atas4.setBackground(Color.blue); tombolatas1.setVisible(false); tombolatas2.setVisible(false); tombolatas3.setVisible(false); tombolbawah2.setVisible(false); tombolbawah3.setVisible(false); tombolbawah4.setVisible(true); } } ); tombolbawah4.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ f.setTitle("bawah 4 action"); atas1.setBackground(Color.red); atas2.setBackground(Color.yellow); atas3.setBackground(Color.green); bawah2.setBackground(Color.blue); bawah3.setBackground(Color.magenta); bawah4.setBackground(Color.white); atas4.setBackground(Color.blue);

//

tombolatas1.setVisible(true); tombolatas2.setVisible(false); tombolatas3.setVisible(false); tombolbawah2.setVisible(false); tombolbawah3.setVisible(false); tombolbawah4.setVisible(false); } } ); f.addWindowListener(new WindowAdapter(){ @Override public void windowClosing(WindowEvent we){ System.exit(0); } }); } public void actionPerformed(ActionEvent e){} }

Вам также может понравиться