Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.UIManager;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JTextField;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JButton;
- import java.awt.Color;
- import javax.swing.JLabel;
- import javax.swing.ImageIcon;
- import javax.swing.SwingConstants;
- @SuppressWarnings("serial")
- public class Frm extends JFrame {
- private JPanel contentPane;
- private JTextField txt1;
- private JTextField txt2;
- private JTextField txtHasil;
- double hasil;
- private JButton Tambah;
- private JButton Kurang;
- private JButton Kali;
- private JButton Bagi;
- private JButton Refresh;
- private JLabel lblIcon;
- /**
- * Create the frame.
- */
- public Frm() {
- setTitle("Kalkulator Ringkas");
- setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 358, 278);
- contentPane = new JPanel();
- contentPane.setBackground(Color.GRAY);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- txt1 = new JTextField();
- txt1.setBounds(12, 25, 233, 28);
- contentPane.add(txt1);
- txt1.setColumns(10);
- txt2 = new JTextField();
- txt2.setColumns(10);
- txt2.setBounds(12, 65, 233, 28);
- contentPane.add(txt2);
- txtHasil = new JTextField();
- txtHasil.setColumns(10);
- txtHasil.setBounds(12, 177, 233, 28);
- contentPane.add(txtHasil);
- Tambah = new JButton("+");
- Tambah.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- hasil = Double.parseDouble(txt1.getText())
- + Double.parseDouble(txt2.getText());
- txtHasil.setText("" + hasil);
- }
- });
- Tambah.setBounds(57, 105, 61, 24);
- contentPane.add(Tambah);
- Kurang = new JButton("-");
- Kurang.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- hasil = Double.parseDouble(txt1.getText())
- - Double.parseDouble(txt2.getText());
- txtHasil.setText("" + hasil);
- }
- });
- Kurang.setBounds(130, 105, 61, 24);
- contentPane.add(Kurang);
- Kali = new JButton("x");
- Kali.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- hasil = Double.parseDouble(txt1.getText())
- * Double.parseDouble(txt2.getText());
- txtHasil.setText("" + hasil);
- }
- });
- Kali.setBounds(57, 141, 61, 24);
- contentPane.add(Kali);
- Bagi = new JButton("/");
- Bagi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- hasil = Double.parseDouble(txt1.getText())
- / Double.parseDouble(txt2.getText());
- txtHasil.setText("" + hasil);
- }
- });
- Bagi.setBounds(130, 141, 61, 24);
- contentPane.add(Bagi);
- Refresh = new JButton("Refresh");
- Refresh.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- txt1.setText("");
- txt2.setText("");
- txtHasil.setText("");
- txt1.requestFocus();
- }
- });
- Refresh.setBounds(12, 217, 94, 24);
- contentPane.add(Refresh);
- lblIcon = new JLabel("Blankon Linux");
- lblIcon.setHorizontalTextPosition(SwingConstants.CENTER);
- lblIcon.setHorizontalAlignment(SwingConstants.CENTER);
- lblIcon.setVerticalTextPosition(SwingConstants.BOTTOM);
- lblIcon.setForeground(new Color(0, 0, 0));
- lblIcon.setIcon(new ImageIcon(Frm.class
- .getResource("/Kalkulator/64x64.png")));
- lblIcon.setBounds(249, 77, 107, 85);
- contentPane.add(lblIcon);
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- UIManager.setLookAndFeel(UIManager
- .getSystemLookAndFeelClassName());
- Frm frame = new Frm();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement