Dibawah ini saya akan berbagi contoh [rogram menggunakan netbeans. sebuah contoh sederhana yang mungkin bermanfaat bagi anda.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TebakAngka extends JFrame implements ActionListener{
JButton bt1=new JButton ("1");
JButton bt2=new JButton ("2");
JButton bt3=new JButton ("3");
JButton bt4=new JButton ("4");
JLabel lbtebak=new JLabel ("");
Random random=new Random ();
int user,comp;
public void actionPerformed(ActionEvent and){
if(and.getSource()==bt1){
user = 1;
}
if(and.getSource()==bt2)user = 2;
if(and.getSource()==bt3)user = 3;
if(and.getSource()==bt4)user = 4;
comp = random.nextInt(4)+1;
if(user == comp)
//JOptionPane.showMessageDialog(null,"TEPAT BRO"+ user);
lbtebak.setText("Anda Benar"+user);
else
//JOptionPane.showMessageDialog(null,"anda salah" + "Pilih no"+comp);
lbtebak.setText("Anda Salah Pilih"+"NO"+comp);
}
public TebakAngka(){//constructor
setVisible(true);
setSize(400,200);
setTitle("TebakAngka");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(null);
bt1.setBounds(10,20,160,40);
bt2.setBounds(180,20,160,40);
bt3.setBounds(10,70,160,40);
bt4.setBounds(180,70,160,40);
add(bt1);add(bt2);add(bt3);add(bt4);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
bt4.addActionListener(this);
add(lbtebak);
lbtebak.setBounds(140,120,160,40);
}
public static void main(String[]args){
new TebakAngka();//call a constructor
}
}
Link penghasil dolar
https://www.bestchange.com/?6=127976