hi, again, my names rezki. its my first time too, leaning in java. i've never know the OOP before, so it's really hard for me to understand and thinking in OO. ok, im working on my home work. its a game about remembering a recipes, i've just started it, so its unfinished. the problem is, I make it some kinda.. just like the procedural programming. how is it? can you hel me to think in OO?
And and the 1st panel, when the cursor touch the area that there should be a button for the second panel, it all appears. it stucks. dear expert, please help me. here's my code :
CODE
public class yuki extends JFrame
{
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(new Runnable()
{public void run(){
new yuki().setVisible(true);
}});
}
public yuki() {
inisialisasi();
}
JPanel panel[];
JLabel halaman01;
JLabel halaman02;
JLabel halaman03;
JButton tombolmasuk;
JButton tombolkeluar, bdk, omsi, omragul, gulai, tegoras, umawa;
private void inisialisasi()
{
panel = new JPanel[4];
panel[0] = new JPanel();
panel[1] = new JPanel();
// panel[2] = new JPanel();
// panel[3] = new JPanel();
// panel[4] = new JPanel();
halaman01 = new JLabel(new ImageIcon("halaman_01.png"));
halaman02 = new JLabel(new ImageIcon("halaman02.png"));
// halaman03 = new JLabel(new ImageIcon("halaman_03.png"));
tombolmasuk = new JButton(new ImageIcon("mulai.png"));
tombolkeluar = new JButton(new ImageIcon("keluar.png"));
//tombol resep
bdk = new JButton(new ImageIcon("bdk.png"));
omsi = new JButton(new ImageIcon("omelet_isi.png"));
omragul = new JButton(new ImageIcon("omragul.png"));
gulai = new JButton(new ImageIcon("gulai_telur.png"));
tegoras = new JButton(new ImageIcon("tegoras.png"));
umawa = new JButton(new ImageIcon("umawa.png"));
//buat kontainer
getContentPane().add(panel[0]);
panel[0].setLayout(null);
panel[0].add(tombolmasuk);
panel[0].add(tombolkeluar);
panel[0].add(halaman01);
//panel 1 isikan tombol resep2
getContentPane().add(panel[1]);
panel[1].setLayout(null);
panel[1].add(bdk);
panel[1].add(omsi);
panel[1].add(omragul);
panel[1].add(gulai);
panel[1].add(tegoras);
panel[1].add(umawa);
panel[1].add(halaman02);
Insets ukuranPanel = getContentPane().getInsets();
panel[0].setBounds(ukuranPanel.left, ukuranPanel.top, 652, 502);
panel[1].setBounds(ukuranPanel.left, ukuranPanel.top, 652, 502);
// panel[1].setVisible(false);
//halaman 1
Dimension masuk = tombolmasuk.getPreferredSize();
Dimension keluar = tombolkeluar.getPreferredSize();
Dimension halaman_1 = halaman01.getPreferredSize();
tombolmasuk.setBounds(200, 400, masuk.width, masuk.height);
tombolkeluar.setBounds(400, 400, keluar.width, keluar.height);
halaman01.setBounds(0, 0, halaman_1.width, halaman_1.height);
//halaman 2
Dimension resep1 = bdk.getPreferredSize();
Dimension resep2 = omsi.getPreferredSize();
Dimension resep3 = omragul.getPreferredSize();
Dimension resep4 = gulai.getPreferredSize();
Dimension resep5 = tegoras.getPreferredSize();
Dimension resep6 = umawa.getPreferredSize();
Dimension halaman_2 = halaman02.getPreferredSize();
bdk.setBounds(68, 100, resep1.width, resep1.height);
omsi.setBounds(68, 170, resep1.width, resep1.height);
omragul.setBounds(68, 240, resep1.width, resep1.height);
gulai.setBounds(374, 100, resep1.width, resep1.height);
tegoras.setBounds(374, 170, resep1.width, resep1.height);
umawa.setBounds(374, 240, resep1.width, resep1.height);
halaman02.setBounds(0, 0, halaman_2.width, halaman_1.height);
tombolmasuk.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
tombolDiKlik(e);
}});
tombolkeluar.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
tombolDiKlik(e);
}});
setSize(652, 502);
setTitle("Yukitamasa Game");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void tombolDiKlik(MouseEvent e)
{
Object x = e.getSource();
if(x == tombolmasuk)
{
panel[0].setVisible(false);
panel[1].setVisible(true);
}
}
}