Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Badguy13 Badguy13 is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 399
Rep Power: 14
Badguy13 mempunyai hidup yang Normal
Default mau nanya program swing dan awt pada java ngga jalan nh

permisi master2 programing sekalian

saya bingung program saya kenapa ngga jalan2 yaa



INI PROGRAMNYA



import javax.swing.JFrame;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JTextField;

import javax.swing.JCheckBox;

import javax.swing.JComboBox;

import java.awt.Font;

import java.awt.Color;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.event.ItemListener;

import java.awt.event.ItemEvent;



class tampilan extends JFrame implements ActionListener {

private int ht, sub, jum;

private double disc, total;

private String [] item = {"","Jakarta","Cirebon","Tasikmalaya"};

private JComboBox tuj = new JComboBox(item);

private JLabel judul = new JLabel("Program Travel Bintang Kejora");

private JLabel nama = new JLabel("nama");

private JLabel tujuan = new JLabel("tujuan");

private JLabel jumlah = new JLabel("jumlah");

private JLabel member = new JLabel("member");

private JCheckBox cb = new JCheckBox ("ya");

private JLabel harga = new JLabel ("harga tiket");

private JLabel sub_t = new JLabel ("sub total");

private JLabel diskon = new JLabel ("diskon");

private JLabel t_harga = new JLabel ("Total harga");

private JTextField txtnama = new JTextField();

private JTextField txtjumlah = new JTextField();

private JTextField txtharga = new JTextField();

private JTextField txtsub = new JTextField();

private JTextField txtdiskon = new JTextField();

private JTextField txttotal = new JTextField();

private JButton hitung = new JButton ("hitung");

private JButton ulangi = new JButton ("ulangi");



tampilan() {

super("program travel ini dibuat oleh GHES");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocation(100,100);

setSize(495,250);

setLayout(null);

add(judul);

add(nama);

add(txtnama);

add(tujuan);

add(tuj);

add(jumlah);

add(txtjumlah);

add(member);

add(cb);

add(harga);

add(txtharga);

add(sub_t);

add(txtsub);

add(diskon);

add(txtdiskon);

add(t_harga);

add(txttotal);

add(hitung);

add(ulangi);

judul.setFont(new Font("times new roman",Font .BOLD,20));

judul.setBounds(10,10,300,20);

nama.setBounds(10,50,100,20);

txtnama.setBounds(120,50,100,20);

tujuan.setBounds(10,100,100,20);

tuj.setBounds(120,75,100,20);

jumlah.setBounds(10,100,100,20);

txtjumlah.setBounds(120,100,100,20);

member.setBounds(10,125,100,20);

cb.setBounds(115,125,100,20);

harga.setBounds(260,50,100,20);

txtharga.setBounds(370,50,100,20);

sub_t.setBounds(260,75,100,20);

txtsub.setBounds(370,75,100,20);

diskon.setBounds(260,100,100,20);

txtdiskon.setBounds(370,100,100,20);

t_harga.setBounds(260,125,100,20);

txttotal.setBounds(370,125,100,20);

hitung.setBounds(130,175,100,20);

ulangi.setBounds(250,175,100,20);

}



public void actionperformed(ActionEvent e) {

String item = (String)tuj.getSelectedItem();

if (item.equals("Jakarta")){

ht = 100000;

}

else if (item.equals("Cirebon")) {

ht = 150000;

}

else if (item.equals("Tasikmalaya")) {

ht = 200000;

}

else {

ht = 0;

}



Object obj = e.getSource();



if (obj == hitung) {

jum = Integer.parseInt(txtjumlah.getText());

sub = jum * ht;

if (cb.isSelected()) {

disc = 0.10 * sub;

}

else {

disc = 0.0 * sub;

}

txtharga.setText("Rp. "+ht);

txtsub.setText("Rp. "+sub);

txtdiskon.setText("Rp. "+disc);

txttotal.setText("Rp. "+total);

}

if (obj == ulangi) {

txtnama.setText("");

txtjumlah.setText("");

txtharga.setText("");

txtsub.setText("");

txtdiskon.setText("");

txttotal.setText("");

}

}

}



public class travel{

public static void main(String args []) {

new tampilan();

}

}







berikut ini errornya gan







makasih banyak jika ada yg ngasih tau sebesarnya

semoga hidup ente makin sukses



thanks



Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 01:45 AM.


no new posts