我不知道为什么会这样。
错误详情
注意:C:\Users\mcsentul\Documents\NetBeansProjects\HitungListrik\src\hitunglistrik\HitungListrik.java
使用未经检查或不安全的操作。
注意:有关详细信息,请重新编译-Xlint:unchecked
。
这是我的代码
public HitungListrik() {
super("PEMBAYARAN REKENING LISTRIK");
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(HitungListrik.class.getName()).log(Level.SEVERE, null, ex);
}
Container konten = getContentPane();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(550, 500);
konten.setBackground(Color.LIGHT_GRAY);
konten.setLayout(null);
// konten.pack();
konten.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
Point mouse = e.getPoint();
System.out.println("tambah" + mouse);
}
@Override
public void mousePressed(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseReleased(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseEntered(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseExited(MouseEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
}
});
combob = new JComboBox();
title = new JLabel("PEMBAYARAN REKENING LISTRIK");
title.setBounds(100, 20, 400, 20);
title.setForeground(Color.BLUE);
title.setFont(new Font("Arial", Font.BOLD, 19));
konten.add(title);
for (int i = 0; i < 13; i++) {
combob.addItem(bulan[count++]);
combob.setBounds(100, 55, 120, 30);
t.setEditable(false);
}
konten.add(t);
konten.add(combob);
combob.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
t.setText((String) ((JComboBox) e.getSource()).getSelectedItem());
}
});
lbulan = new JLabel("Bulan ");
lbulan.setBounds(40, 55, 80, 30);
lbulan.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lbulan);
String msg;
msg = "No image";
ImageIcon image = new ImageIcon(getClass().getClassLoader().getResource("image/pln.png"));
lgbr = new JLabel(image);
if (image != null) {
lgbr.setIcon(image);
lgbr.setText("");
} else {
lgbr.setText(msg);
System.out.println(msg);
}
lgbr.setBounds(460, 5, 60, 50);
lgbr.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lgbr);
lbiayaperkwh = new JLabel("Biaya Per Kwh ");
lbiayaperkwh.setBounds(240, 55, 120, 30);
lbiayaperkwh.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lbiayaperkwh);
tkwh = new JTextField();
tkwh.setBounds(340, 55, 150, 30);
tkwh.setEditable(false);
konten.add(tkwh);
lbulan = new JLabel("Daya ");
lbulan.setBounds(40, 100, 80, 30);
lbulan.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lbulan);
v450 = new JCheckBox("450 Volt Ampere", false);
konten.add(v450).setBounds(100, 110, 120, 20);
v450.addItemListener(new mainAction());
// jenisantrian = new JCheckBoxGroup();
v900 = new JCheckBox("900 Volt Ampere", false);
konten.add(v900).setBounds(100, 140, 120, 20);
v900.addItemListener(new mainAction());
v1350 = new JCheckBox("1350 Volt Ampere", false);
konten.add(v1350).setBounds(100, 170, 120, 20);
v1350.addItemListener(new mainAction());
labodemen = new JLabel("Abodemen");
// labodemen.setIcon(imgThisImg);
labodemen.setBounds(40, 220, 120, 30);
labodemen.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(labodemen);
tabodemen = new JTextField();
tabodemen.setBounds(120, 220, 100, 30);
tabodemen.setEditable(false);
konten.add(tabodemen);
bhitung = new JButton("Hitung");
bhitung.setBounds(40, 300, 100, 30);
bhitung.addActionListener(new HitungListrik.mainAction());
konten.add(bhitung);
blagi = new JButton("Lagi");
blagi.setBounds(150, 300, 100, 30);
blagi.addActionListener(new HitungListrik.mainAction());
konten.add(blagi);
///
ljumlah = new JLabel("Jumlah");
ljumlah.setBounds(240, 100, 120, 30);
ljumlah.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(ljumlah);
tjumlah = new JTextField();
tjumlah.setBounds(340, 100, 150, 30);
tjumlah.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((c >= '0') && (c <= '9')
|| (c == KeyEvent.VK_BACK_SPACE)
|| (c == KeyEvent.VK_DELETE))) {
getToolkit().beep();
e.consume();
}
}
});
konten.add(tjumlah);
ltagihan = new JLabel("Tagihan");
ltagihan.setBounds(240, 140, 120, 30);
ltagihan.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(ltagihan);
ttagihan = new JTextField();
ttagihan.setBounds(340, 140, 150, 30);
ttagihan.setEditable(false);
konten.add(ttagihan);
lpajak = new JLabel("Pajak 10%");
lpajak.setBounds(240, 180, 120, 30);
lpajak.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lpajak);
tpajak = new JTextField();
tpajak.setBounds(340, 180, 150, 30);
tpajak.setEditable(false);
konten.add(tpajak);
ltotal = new JLabel("Total");
ltotal.setBounds(240, 220, 120, 30);
ltotal.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(ltotal);
ttotal = new JTextField();
ttotal.setBounds(340, 220, 150, 30);
ttotal.setEditable(false);
konten.add(ttotal);
luang = new JLabel("Uang cash");
luang.setBounds(300, 300, 80, 30);
luang.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(luang);
tuang = new JTextField();
tuang.setBounds(390, 300, 110, 30);
tuang.addActionListener(new HitungListrik.mainAction());
tuang.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((c >= '0') && (c <= '9')
|| (c == KeyEvent.VK_BACK_SPACE)
|| (c == KeyEvent.VK_DELETE))) {
getToolkit().beep();
e.consume();
}
}
});
konten.add(tuang);
lkembali = new JLabel("Uang kembali");
lkembali.setBounds(300, 340, 100, 30);
lkembali.setFont(new Font("Serif", Font.PLAIN, 15));
konten.add(lkembali);
tkembali = new JTextField();
tkembali.setBounds(390, 340, 110, 30);
tkembali.setEditable(false);
konten.add(tkembali);
bhapus = new JButton("Hapus");
bhapus.setBounds(70, 400, 100, 40);
bhapus.setFont(new Font("Serif", Font.PLAIN, 17));
bhapus.addActionListener(new HitungListrik.mainAction());
konten.add(bhapus);
bkeluar = new JButton("Keluar");
bkeluar.setBounds(330, 400, 100, 40);
bkeluar.setFont(new Font("Serif", Font.PLAIN, 17));
bkeluar.addActionListener(new HitungListrik.mainAction());
konten.add(bkeluar);
}
class mainAction implements ItemListener, ActionListener {
@Override
public void itemStateChanged(ItemEvent ev) {
if (ev.getStateChange() == ItemEvent.SELECTED) {
// cb1.setEnabled(false);
}
Object pilihan = ev.getItemSelectable();
if (pilihan == v450) {
tabodemen.setText("25000");
tkwh.setText("250");
daya = "450 Volt Ampere";
v900.setEnabled(false);
v1350.setEnabled(false);
if (v450.isSelected() == false) {
daya = "";
tabodemen.setText("");
tkwh.setText("");
v900.setEnabled(true);
v1350.setEnabled(true);
}
} else if (pilihan == v900) {
tabodemen.setText("35000");
daya = "900 Volt Ampere";
tkwh.setText("350");
v450.setEnabled(false);
v1350.setEnabled(false);
if (v900.isSelected() == false) {
daya = "";
tabodemen.setText("");
tkwh.setText("");
v450.setEnabled(true);
v1350.setEnabled(true);
}
} else if (pilihan == v1350) {
tabodemen.setText("45000");
daya = "1350 Volt Ampere";
tkwh.setText("450");
v450.setEnabled(false);
v900.setEnabled(false);
if (v1350.isSelected() == false) {
daya = "";
tabodemen.setText("");
tkwh.setText("");
v900.setEnabled(true);
v450.setEnabled(true);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bhitung) {
if ("".equals(t.getText().trim())) {
String peringatan = "Anda belum memilih bulan";
JOptionPane.showMessageDialog(null, peringatan);
} else if ("".equals(tjumlah.getText().trim())) {
String peringatan = "Isi jumlah penggunaan KWH";
JOptionPane.showMessageDialog(null, peringatan);
} else {
System.out.println("=============================================");
System.out.println(" Tagihan bulan " + t.getText().trim());
System.out.println("=============================================");
System.out.println(t.getText().trim());
String sjumlah = tjumlah.getText().trim();
int ijumlah = Integer.parseInt(sjumlah);
String skwh = tkwh.getText().trim();
int ikwh = Integer.parseInt(skwh);
int tagihan = ijumlah * ikwh;
double pajak = tagihan * 0.1;
ttagihan.setText(String.valueOf(tagihan));
tpajak.setText(String.valueOf(pajak));
total = tagihan + pajak;
bayar = tkembali.getText().trim();
NumberFormat f = NumberFormat.getInstance();
f.setGroupingUsed(false);
String r = f.format(total);
ttotal.setText(String.valueOf(r));
System.out.println("Jumlah Daya : " + daya);
System.out.println("Biaya Per KWH : " + ikwh);
System.out.println("Jumlah KWH : " + ijumlah);
System.out.println("Pajak : " + pajak);
System.out.println("Total yang harus dibayar : " + total);
}
}
if (e.getSource() == blagi) {
v900.setEnabled(true);
v1350.setEnabled(true);
v450.setEnabled(true);
v450.setSelected(false);
v900.setSelected(false);
v1350.setSelected(false);
combob.setSelectedIndex(0);
tkwh.setText("");
ttotal.setText("");
tpajak.setText("");
tjumlah.setText("");
tabodemen.setText("");
ttagihan.setText("");
}
if (e.getSource() == bhapus) {
v900.setEnabled(true);
v1350.setEnabled(true);
v450.setEnabled(true);
v450.setSelected(false);
v900.setSelected(false);
v1350.setSelected(false);
combob.setSelectedIndex(0);
tkwh.setText("");
ttotal.setText("");
tpajak.setText("");
tjumlah.setText("");
tuang.setText("");
tkembali.setText("");
tabodemen.setText("");
ttagihan.setText("");
}
if (e.getSource() == bkeluar) {
int selectedOption = JOptionPane.showConfirmDialog(null,
"Anda yakin mau keluar?",
"Choose",
JOptionPane.YES_NO_OPTION);
if (selectedOption == JOptionPane.YES_OPTION) {
System.exit(0);
}
// System.out.println("tambah");
}
if (e.getSource() == tuang) {
if ("".equals(tuang.getText().trim())) {
String peringatan = "Anda belum mengisi jumlah uang yang diberikan User";
JOptionPane.showMessageDialog(null, peringatan);
} else {
String uang = tuang.getText().trim();
int iuang = Integer.parseInt(uang);
double kembali = iuang - total;
if ((total - 0) <= 0) {
String peringatan = "Belum ada data";
JOptionPane.showMessageDialog(null, peringatan);
} else if (iuang < total) {
String peringatan = "Uang yang anda masukkan lebih kecil dari Total yang harus dibayarkan";
JOptionPane.showMessageDialog(null, peringatan);
} else {
bayar = uang;
System.out.println("Bayar : " + bayar);
System.out.println("Kembali : " + kembali);
Date date = new Date();
System.out.println("=============================================");
System.out.println("+ " + date + " +");
System.out.println("=============================================");
tkembali.setText(String.valueOf(kembali));
}
}
}
}
}
}
class test {//main
public static void main(String[] args) {
Date date = new Date();
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("+ Log " + date + " +");
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++");
HitungListrik a = new HitungListrik();//create frame
a.setResizable(false);//agar tidak bisa di perbesar
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int x = (dim.width - a.getSize().width) / 2;
int y = (dim.height - a.getSize().height) / 2;
a.setLocation(x, y);
}//end method
}//end class