Created
September 30, 2015 06:05
-
-
Save resarahadian/352103358256f488ef86 to your computer and use it in GitHub Desktop.
Aplikasi Konversi Berat Sederhana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.EventQueue; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ActionEvent; | |
import javax.swing.ImageIcon; | |
import java.awt.Font; | |
import java.awt.Color; | |
@SuppressWarnings(“serial”) | |
public class KonversiBeratApp extends JFrame { | |
private JPanel contentPane; | |
private JLabel lblKilogram; | |
private JLabel lblGram; | |
private JLabel lblOns; | |
private JTextField txtKg; | |
private JTextField txtGram; | |
private JTextField txtOns; | |
double kg, gram, ons; | |
private JLabel lblIcon; | |
/** | |
* Create the frame. | |
*/ | |
public KonversiBeratApp() { | |
setTitle(“Konversi Berat”); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 450, 300); | |
contentPane = new JPanel(); | |
contentPane.setBackground(new Color(245, 222, 179)); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
lblKilogram = new JLabel(“Kilogram”); | |
lblKilogram.setFont(new Font(“Tahoma”, Font.BOLD, 10)); | |
lblKilogram.setBounds(87, 80, 46, 14); | |
contentPane.add(lblKilogram); | |
lblGram = new JLabel(“Gram”); | |
lblGram.setFont(new Font(“Tahoma”, Font.BOLD, 10)); | |
lblGram.setBounds(87, 111, 46, 14); | |
contentPane.add(lblGram); | |
lblOns = new JLabel(“Ons”); | |
lblOns.setFont(new Font(“Tahoma”, Font.BOLD, 10)); | |
lblOns.setBounds(87, 142, 46, 14); | |
contentPane.add(lblOns); | |
txtKg = new JTextField(); | |
txtKg.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
gram = Double.parseDouble(txtKg.getText()) * 1000; | |
ons = Double.parseDouble(txtKg.getText()) / 10; | |
txtGram.setText(“” + gram); | |
txtOns.setText(“” + ons); | |
} | |
}); | |
txtKg.setBounds(143, 77, 117, 20); | |
contentPane.add(txtKg); | |
txtKg.setColumns(10); | |
txtGram = new JTextField(); | |
txtGram.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
kg = Double.parseDouble(txtGram.getText()) / 1000; | |
ons = Double.parseDouble(txtGram.getText()) / 100; | |
txtKg.setText(“” + kg); | |
txtOns.setText(“” + ons); | |
} | |
}); | |
txtGram.setBounds(143, 108, 117, 20); | |
contentPane.add(txtGram); | |
txtGram.setColumns(10); | |
txtOns = new JTextField(); | |
txtOns.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent arg0) { | |
kg = Double.parseDouble(txtOns.getText()) / 10; | |
gram = Double.parseDouble(txtOns.getText()) * 100; | |
txtKg.setText(“” + kg); | |
txtGram.setText(“” + gram); | |
} | |
}); | |
txtOns.setBounds(143, 139, 117, 20); | |
contentPane.add(txtOns); | |
txtOns.setColumns(10); | |
lblIcon = new JLabel(“”); | |
lblIcon.setIcon(new ImageIcon(KonversiBeratApp.class | |
.getResource(“/KonversiBerat/truck.png”))); | |
lblIcon.setBounds(72, 47, 333, 201); | |
contentPane.add(lblIcon); | |
setLocationRelativeTo(null); | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
KonversiBeratApp frame = new KonversiBeratApp(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment