daily gadgets, computers, and electronic news
04/04
2005

Java oh Java

Sponsored Links

Heh, udah lama gak pegang Java kyknya jadi bloon lagi neh <_ < :(
Ngerjain tugas Aplin yg sederhana aja butuh waktu 2 jam :o
itupun liat code-nya aja keliatan kyk bikinin orang baru belajar Java, hehehe


check it out:

[java]import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class tugas1 extends JFrame implements ActionListener {

static JButton btn1 = new JButton(”Hello”);
static JButton btn2 = new JButton(”World”);
static JButton btn3 = new JButton(”Everyone”);
JButton btnClose = new JButton(”Close”);
JFrame child = null;

public void showWindow(String str) {
child = new JFrame();
child.setTitle(str);
child.setLocation(200,200); child.setSize(150,150);
child.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
child.getContentPane().setLayout(new BorderLayout());
child.add(new JLabel(” “),BorderLayout.SOUTH);
child.add(new JLabel(” “),BorderLayout.EAST);
child.add(new JLabel(” “),BorderLayout.WEST);
child.add(new JLabel(” “),BorderLayout.NORTH);
JPanel pnl = new JPanel(new GridLayout(2,1));
child.add(pnl,BorderLayout.CENTER);
pnl.add(new JLabel(str,SwingConstants.CENTER));
pnl.add(btnClose);
btnClose.addActionListener(this);
child.setVisible(true);
}

tugas1() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(new BorderLayout());
add(new JLabel(” “),BorderLayout.SOUTH);
add(new JLabel(” “),BorderLayout.EAST);
add(new JLabel(” “),BorderLayout.WEST);
add(new JLabel(” “),BorderLayout.NORTH);
JPanel pnl = new JPanel(new GridLayout(5,1));
add(pnl,BorderLayout.CENTER);
pnl.add(btn1); pnl.add(new JLabel(”")); pnl.add(btn2); pnl.add(new JLabel(”")); pnl.add(btn3);
btn1.addActionListener(this); btn2.addActionListener(this); btn3.addActionListener(this);
}

public static void main(String[] args) {
tugas1 app = new tugas1();
app.setTitle(”Aplikasi Internet”);
app.setLocation(100,100); app.setSize(200,200);
app.setVisible(true);
}

public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source==btn1) showWindow(btn1.getText());
else if(source==btn2) showWindow(btn2.getText());
else if(source==btn3) showWindow(btn3.getText());
else if(source==btnClose) child.dispose();
}

}[/java]

Java oh Java is written by cosa and posted under Personal Rants, Programming . If you like it, you might consider subscribing to our feed, follows us on Twitter, or receive our latest posts via email. Or else, you could also or store it to your favourite social bookmark sites. Further information about this article can be found.

2 Comments »

No comments yet.

Leave a comment