asalamualaikum wr..wb..
pada kesempatan kali ini saya akan share perogram java saya yang berjudul"aplikasi perhitungan bagun ruang..
oke,langsung saja kita ke codingnya..
FRAME UTAMA
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.JLabel;
/**
*
* @author hasan basri
*/
public class Hitungbngun extends JFrame implements ActionListener {
JFileChooser FileChooser = new JFileChooser();
Mp3Filter filter = new Mp3Filter();
ArrayList listSong = new ArrayList();
JTextField text1 = new JTextField (20);
JMenu mnukubus = new JMenu ("kubus");
JMenu mnubalok = new JMenu ("balok");
JMenu mnutabung = new JMenu ("tabung");
JMenu mnulimas = new JMenu ("limas");
JMenu mnubola = new JMenu ("bola");
JMenu mnukerucut = new JMenu ("kerucut");
JMenu mnuprisma = new JMenu ("prisma");
JMenu mnuabout = new JMenu ("About");
JMenuItem open = new JMenuItem("Open");
JMenuItem itmvlume = new JMenuItem("volume kubus");
JMenuItem itmluas = new JMenuItem("Luas kubus");
JMenuItem itmvlumeblk = new JMenuItem("volume balok");
JMenuItem itmluasblk = new JMenuItem("Luas balok");
JMenuItem itmvlumetbg = new JMenuItem("volume tabung");
JMenuItem itmluastbg = new JMenuItem("Luas tabung");
JMenuItem itmvlumelms = new JMenuItem("volume limas");
JMenuItem itmluaslms = new JMenuItem("Luas limas");
JMenuItem itmvlumebola = new JMenuItem("volume bola");
JMenuItem itmluasbola = new JMenuItem("Luas bola");
JMenuItem itmvlumekrt = new JMenuItem("volume kerucut");
JMenuItem itmluaskrt = new JMenuItem("Luas kerucut");
JMenuItem itmvlumeprm = new JMenuItem("volume prisma");
JMenuItem itmluasprm = new JMenuItem("Luas prisma");
JMenuItem itmaboutApp= new JMenuItem ("About Application");
JMenuItem itmaboutAuthor = new JMenuItem ("About Author");
JLabel lblNewLabel = new JLabel();
JLabel lblNewLabel1 = new JLabel();
JLabel lblNewLabel2 = new JLabel(new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/bangunruang2.jpg")));
JDesktopPane desk = new JDesktopPane();
public Hitungbngun () {
setTitle ("APLIKASI PERHITUNGAN BANGUN RUANG");
setSize (920,400);
setIconImage(Toolkit.getDefaultToolkit().getImage("/Bahan Ngajar/program java/Hitungbngun/src/hitungbngun/lintasberita-32x32.gif"));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible (true);
Buatmenu();
component();
}
void Buatmenu(){
JMenuBar barismenu = new JMenuBar();
barismenu.setBackground(Color.red);
setJMenuBar(barismenu);
barismenu.add(mnukubus);
mnukubus.setBackground(Color.ORANGE);
barismenu.add(mnubalok);
mnubalok.setBackground(Color.BLUE);
barismenu.add(mnutabung);
mnutabung.setBackground(Color.CYAN);
barismenu.add(mnulimas);
mnulimas.setBackground(Color.DARK_GRAY);
barismenu.add(mnubola);
mnubola.setBackground(Color.GRAY);
barismenu.add(mnukerucut);
mnukerucut.setBackground(Color.GREEN);
barismenu.add(mnuprisma);
mnuprisma.setBackground(Color.MAGENTA);
barismenu.add(mnuabout);
mnuabout.setBackground(Color.YELLOW);
mnukubus.add(itmvlume).setBackground(Color.red);
mnukubus.add(itmluas).setBackground(Color.BLUE);
mnukubus.add(open).setBackground(Color.BLUE);
mnubalok.add(itmvlumeblk).setBackground(Color.red);
mnubalok.add(itmluasblk).setBackground(Color.ORANGE);
mnutabung.add(itmvlumetbg).setBackground(Color.GREEN);
mnutabung.add(itmluastbg).setBackground(Color.YELLOW);
mnulimas.add(itmvlumelms).setBackground(Color.PINK);
mnulimas.add(itmluaslms).setBackground(Color.orange);
mnubola.add(itmvlumebola).setBackground(Color.white);
mnubola.add(itmluasbola).setBackground(Color.red);
mnukerucut.add(itmvlumekrt).setBackground(Color.yellow);
mnukerucut.add(itmluaskrt).setBackground(Color.BLUE);
mnuprisma.add(itmvlumeprm).setBackground(Color.red);
mnuprisma.add(itmluasprm).setBackground(Color.GREEN);
mnuabout.add(itmaboutApp).setBackground(Color.GREEN);
mnuabout.add(itmaboutAuthor).setBackground(Color.BLUE);
getContentPane().add(lblNewLabel2);
add(lblNewLabel2, BorderLayout.EAST);
lblNewLabel2.setBounds(20,80,70,20);
getContentPane().setBackground(Color.getColor(null, Color.TRANSLUCENT));
desk.setBackground(Color.GREEN);
itmvlume.addActionListener(this);
itmvlumeblk.addActionListener(this);
itmvlumetbg.addActionListener(this);
itmvlumelms.addActionListener(this);
itmluas.addActionListener(this);
itmluasblk.addActionListener(this);
itmluastbg.addActionListener(this);
itmluaslms.addActionListener(this);
itmluasbola.addActionListener(this);
itmluaskrt.addActionListener(this);
itmvlumebola.addActionListener(this);
itmvlumekrt.addActionListener(this);
itmaboutApp.addActionListener(this);
itmaboutAuthor.addActionListener(this);
itmvlumeprm.addActionListener(this);
itmluasprm.addActionListener(this);
open.addActionListener(this);
}
void component () {
getContentPane().add(desk);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==itmvlume){
Vlmekbs h = new Vlmekbs();
desk.add(h);
h.show();
}
else if (e.getSource()==itmvlumeblk){
vlmeblk s = new vlmeblk();
desk.add(s);
s.show();
}
else if (e.getSource()==itmvlumetbg){
vlmetbg n = new vlmetbg();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluas){
luaskbs n = new luaskbs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasblk){
luasblk n = new luasblk();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluastbg){
luastbg n = new luastbg();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluaslms){
luaslms n = new luaslms();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumelms){
vlmelms n = new vlmelms();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumebola){
Vlumebola n = new Vlumebola();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumekrt){
vlmekrc n = new vlmekrc();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasbola){
luasbola n = new luasbola();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluaskrt){
luaskrc n = new luaskrc();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumeprm){
vlumeprs n = new vlumeprs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasprm){
luasprs n = new luasprs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmaboutAuthor){
Full n = new Full();
desk.add(n);
n.show();
}
else if (e.getSource()==itmaboutApp){
App n = new App();
desk.add(n);
n.show();
}
else if (e.getSource()==open){
FileChooser.setFileFilter(filter);
FileChooser.setMultiSelectionEnabled(true);
int fileValid = FileChooser.showOpenDialog(open);
if (fileValid == javax.swing.JFileChooser.CANCEL_OPTION) {
return;
}
else if(fileValid == javax.swing.JFileChooser.APPROVE_OPTION) {
File file = FileChooser.getSelectedFile();
listSong.add(file);
}
}
}
public static void main (String[]args){
Hitungbngun m = new Hitungbngun ();
}
}
setelah frame utama kita buat internalframenya..
INTERNAL FRAME LUAS BALOK
import java.awt.*;
import java.awt.event.*;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class luasblk extends JInternalFrame implements ActionListener {
TextField txtPanjang, txtLebar, txtHasil,txttinggi,txtrms;
Button btnHitung,btnReset,btnSimpan;
Label lblPanjang, lblLebar, lblHasil,lbltinggi,lblrms;
double hasil;
DefaultListModel lmodel;
JList list = new JList();
public luasblk(){
super("Luas balok",true,true,true,true);
Icon h = null;
try {
h = new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/balok.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
setFrameIcon(h);
Panel panelhasan = new Panel();
Panel panelbasri = new Panel();
Panel panelhb = new Panel();
lmodel = new DefaultListModel();
list = new JList(lmodel);
JScrollPane scroll = new JScrollPane(list);
scroll.setBounds(30,40,50,20);
this.add(scroll);
panelhasan.setLayout(new GridLayout(7, 1));
panelhasan.add(lblPanjang = new Label("Panjang: "));
panelhasan.add(lblLebar = new Label("Lebar: "));
panelhasan.add(lbltinggi = new Label("tinggi: "));
panelhasan.add(new Label());
panelhasan.add(lblHasil = new Label("Volume: "));
panelhasan.add(lblrms = new Label("RUMUS: "));
panelbasri.setLayout(new GridLayout(7, 1));
panelbasri.add(txtPanjang = new TextField(""));
panelbasri.add(txtLebar = new TextField());
panelbasri.add(txttinggi = new TextField());
panelbasri.add(btnHitung = new Button("Hitung"));
btnHitung.setBackground(Color.red);
panelbasri.add(txtHasil = new TextField());
panelbasri.add(txtrms = new TextField("2*(P*L+L*T+P*T)"));
panelhb.setLayout(new GridLayout(4, 1));
panelhb.add(btnReset=new Button("Reset"));
btnReset.setBackground(Color.red);
panelhb.add(btnSimpan=new Button("Simpan"));
btnSimpan.setBackground(Color.red);
panelhb.add(scroll);
getContentPane().setBackground(Color.red);
btnHitung.addActionListener(this);
btnSimpan.addActionListener(this);
btnReset.addActionListener(this);
add(panelhasan, BorderLayout.WEST);
add(panelbasri, BorderLayout.CENTER);
add(panelhb, BorderLayout.EAST);
setSize(500,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(btnHitung)) {
hasil = 2 * (Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txtLebar.getText())
+Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txttinggi.getText())+
Double.parseDouble(txttinggi.getText()) * Double.parseDouble(txtLebar.getText()));
txtHasil.setText(""+hasil);
}else if(e.getSource() == btnSimpan){
lmodel.addElement("Panjang :" + txtPanjang.getText());
lmodel.addElement("Lebar :" + txtLebar.getText());
lmodel.addElement("tinggi :" + txttinggi.getText());
lmodel.addElement("Luas Balok :" + txtHasil.getText());
}else if(e.getSource() == btnReset){
txtPanjang.setText(" ");
txtLebar.setText(" ");
txttinggi.setText(" ");
txtHasil.setText(" ");
}else {
this.dispose();
}
}
}
INTERNAL FRAME VOLUME BALOK
import java.awt.*;
import java.awt.event.*;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class vlmeblk extends JInternalFrame implements ActionListener {
TextField txtPanjang, txtLebar, txtHasil,txttinggi,txtrms;
Button btnHitung,btnReset,btnSimpan;
Label lblPanjang, lblLebar, lblHasil,lbltinggi,lblrms;
double hasil;
DefaultListModel lmodel;
JList list = new JList();
public vlmeblk(){
super("volume balok",true,true,true,true);
Icon h = null;
try {
h = new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/balok.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
setFrameIcon(h);
Panel panelhasan = new Panel();
Panel panelbasri = new Panel();
Panel panelhb = new Panel();
lmodel = new DefaultListModel();
list = new JList(lmodel);
JScrollPane scroll = new JScrollPane(list);
scroll.setBounds(30,40,50,20);
this.add(scroll);
panelhasan.setLayout(new GridLayout(7, 1));
panelhasan.add(lblPanjang = new Label("Panjang: "));
panelhasan.add(lblLebar = new Label("Lebar: "));
panelhasan.add(lbltinggi = new Label("tinggi: "));
panelhasan.add(new Label());
panelhasan.add(lblHasil = new Label("Volume: "));
panelhasan.add(lblrms = new Label("RUMUS: "));
panelbasri.setLayout(new GridLayout(7, 1));
panelbasri.add(txtPanjang = new TextField(""));
panelbasri.add(txtLebar = new TextField());
panelbasri.add(txttinggi = new TextField());
panelbasri.add(btnHitung = new Button("Hitung"));
btnHitung.setBackground(Color.red);
panelbasri.add(txtHasil = new TextField());
panelbasri.add(txtrms = new TextField("panjang*lebar*tinggi"));
panelhb.setLayout(new GridLayout(4, 1));
panelhb.add(btnReset=new Button("Reset"));
btnReset.setBackground(Color.red);
panelhb.add(btnSimpan=new Button("Simpan"));
btnSimpan.setBackground(Color.red);
panelhb.add(scroll);
getContentPane().setBackground(Color.red);
btnHitung.addActionListener(this);
btnSimpan.addActionListener(this);
btnReset.addActionListener(this);
add(panelhasan, BorderLayout.WEST);
add(panelbasri, BorderLayout.CENTER);
add(panelhb, BorderLayout.EAST);
setSize(500,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(btnHitung)) {
hasil = Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txtLebar.getText()) *
Double.parseDouble(txttinggi.getText());
txtHasil.setText(""+hasil);
}else if(e.getSource() == btnSimpan){
lmodel.addElement("Panjang :" + txtPanjang.getText());
lmodel.addElement("Lebar :" + txtLebar.getText());
lmodel.addElement("tinggi :" + txttinggi.getText());
lmodel.addElement("Volume Balok :" + txtHasil.getText());
}else if(e.getSource() == btnReset){
txtPanjang.setText(" ");
txtLebar.setText(" ");
txttinggi.setText(" ");
txtHasil.setText(" ");
}else {
this.dispose();
}
}
}
selanjutnya buat internal frame luas dan volume kubus,luas dan volume kerucut,luas dan volume bola dll..
untuk lebih jelas download saja projeknya DISINI
adapun hasinya seperti ini
pada kesempatan kali ini saya akan share perogram java saya yang berjudul"aplikasi perhitungan bagun ruang..
oke,langsung saja kita ke codingnya..
FRAME UTAMA
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.JLabel;
/**
*
* @author hasan basri
*/
public class Hitungbngun extends JFrame implements ActionListener {
JFileChooser FileChooser = new JFileChooser();
Mp3Filter filter = new Mp3Filter();
ArrayList listSong = new ArrayList();
JTextField text1 = new JTextField (20);
JMenu mnukubus = new JMenu ("kubus");
JMenu mnubalok = new JMenu ("balok");
JMenu mnutabung = new JMenu ("tabung");
JMenu mnulimas = new JMenu ("limas");
JMenu mnubola = new JMenu ("bola");
JMenu mnukerucut = new JMenu ("kerucut");
JMenu mnuprisma = new JMenu ("prisma");
JMenu mnuabout = new JMenu ("About");
JMenuItem open = new JMenuItem("Open");
JMenuItem itmvlume = new JMenuItem("volume kubus");
JMenuItem itmluas = new JMenuItem("Luas kubus");
JMenuItem itmvlumeblk = new JMenuItem("volume balok");
JMenuItem itmluasblk = new JMenuItem("Luas balok");
JMenuItem itmvlumetbg = new JMenuItem("volume tabung");
JMenuItem itmluastbg = new JMenuItem("Luas tabung");
JMenuItem itmvlumelms = new JMenuItem("volume limas");
JMenuItem itmluaslms = new JMenuItem("Luas limas");
JMenuItem itmvlumebola = new JMenuItem("volume bola");
JMenuItem itmluasbola = new JMenuItem("Luas bola");
JMenuItem itmvlumekrt = new JMenuItem("volume kerucut");
JMenuItem itmluaskrt = new JMenuItem("Luas kerucut");
JMenuItem itmvlumeprm = new JMenuItem("volume prisma");
JMenuItem itmluasprm = new JMenuItem("Luas prisma");
JMenuItem itmaboutApp= new JMenuItem ("About Application");
JMenuItem itmaboutAuthor = new JMenuItem ("About Author");
JLabel lblNewLabel = new JLabel();
JLabel lblNewLabel1 = new JLabel();
JLabel lblNewLabel2 = new JLabel(new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/bangunruang2.jpg")));
JDesktopPane desk = new JDesktopPane();
public Hitungbngun () {
setTitle ("APLIKASI PERHITUNGAN BANGUN RUANG");
setSize (920,400);
setIconImage(Toolkit.getDefaultToolkit().getImage("/Bahan Ngajar/program java/Hitungbngun/src/hitungbngun/lintasberita-32x32.gif"));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible (true);
Buatmenu();
component();
}
void Buatmenu(){
JMenuBar barismenu = new JMenuBar();
barismenu.setBackground(Color.red);
setJMenuBar(barismenu);
barismenu.add(mnukubus);
mnukubus.setBackground(Color.ORANGE);
barismenu.add(mnubalok);
mnubalok.setBackground(Color.BLUE);
barismenu.add(mnutabung);
mnutabung.setBackground(Color.CYAN);
barismenu.add(mnulimas);
mnulimas.setBackground(Color.DARK_GRAY);
barismenu.add(mnubola);
mnubola.setBackground(Color.GRAY);
barismenu.add(mnukerucut);
mnukerucut.setBackground(Color.GREEN);
barismenu.add(mnuprisma);
mnuprisma.setBackground(Color.MAGENTA);
barismenu.add(mnuabout);
mnuabout.setBackground(Color.YELLOW);
mnukubus.add(itmvlume).setBackground(Color.red);
mnukubus.add(itmluas).setBackground(Color.BLUE);
mnukubus.add(open).setBackground(Color.BLUE);
mnubalok.add(itmvlumeblk).setBackground(Color.red);
mnubalok.add(itmluasblk).setBackground(Color.ORANGE);
mnutabung.add(itmvlumetbg).setBackground(Color.GREEN);
mnutabung.add(itmluastbg).setBackground(Color.YELLOW);
mnulimas.add(itmvlumelms).setBackground(Color.PINK);
mnulimas.add(itmluaslms).setBackground(Color.orange);
mnubola.add(itmvlumebola).setBackground(Color.white);
mnubola.add(itmluasbola).setBackground(Color.red);
mnukerucut.add(itmvlumekrt).setBackground(Color.yellow);
mnukerucut.add(itmluaskrt).setBackground(Color.BLUE);
mnuprisma.add(itmvlumeprm).setBackground(Color.red);
mnuprisma.add(itmluasprm).setBackground(Color.GREEN);
mnuabout.add(itmaboutApp).setBackground(Color.GREEN);
mnuabout.add(itmaboutAuthor).setBackground(Color.BLUE);
getContentPane().add(lblNewLabel2);
add(lblNewLabel2, BorderLayout.EAST);
lblNewLabel2.setBounds(20,80,70,20);
getContentPane().setBackground(Color.getColor(null, Color.TRANSLUCENT));
desk.setBackground(Color.GREEN);
itmvlume.addActionListener(this);
itmvlumeblk.addActionListener(this);
itmvlumetbg.addActionListener(this);
itmvlumelms.addActionListener(this);
itmluas.addActionListener(this);
itmluasblk.addActionListener(this);
itmluastbg.addActionListener(this);
itmluaslms.addActionListener(this);
itmluasbola.addActionListener(this);
itmluaskrt.addActionListener(this);
itmvlumebola.addActionListener(this);
itmvlumekrt.addActionListener(this);
itmaboutApp.addActionListener(this);
itmaboutAuthor.addActionListener(this);
itmvlumeprm.addActionListener(this);
itmluasprm.addActionListener(this);
open.addActionListener(this);
}
void component () {
getContentPane().add(desk);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==itmvlume){
Vlmekbs h = new Vlmekbs();
desk.add(h);
h.show();
}
else if (e.getSource()==itmvlumeblk){
vlmeblk s = new vlmeblk();
desk.add(s);
s.show();
}
else if (e.getSource()==itmvlumetbg){
vlmetbg n = new vlmetbg();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluas){
luaskbs n = new luaskbs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasblk){
luasblk n = new luasblk();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluastbg){
luastbg n = new luastbg();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluaslms){
luaslms n = new luaslms();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumelms){
vlmelms n = new vlmelms();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumebola){
Vlumebola n = new Vlumebola();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumekrt){
vlmekrc n = new vlmekrc();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasbola){
luasbola n = new luasbola();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluaskrt){
luaskrc n = new luaskrc();
desk.add(n);
n.show();
}
else if (e.getSource()==itmvlumeprm){
vlumeprs n = new vlumeprs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmluasprm){
luasprs n = new luasprs();
desk.add(n);
n.show();
}
else if (e.getSource()==itmaboutAuthor){
Full n = new Full();
desk.add(n);
n.show();
}
else if (e.getSource()==itmaboutApp){
App n = new App();
desk.add(n);
n.show();
}
else if (e.getSource()==open){
FileChooser.setFileFilter(filter);
FileChooser.setMultiSelectionEnabled(true);
int fileValid = FileChooser.showOpenDialog(open);
if (fileValid == javax.swing.JFileChooser.CANCEL_OPTION) {
return;
}
else if(fileValid == javax.swing.JFileChooser.APPROVE_OPTION) {
File file = FileChooser.getSelectedFile();
listSong.add(file);
}
}
}
public static void main (String[]args){
Hitungbngun m = new Hitungbngun ();
}
}
setelah frame utama kita buat internalframenya..
INTERNAL FRAME LUAS BALOK
import java.awt.*;
import java.awt.event.*;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class luasblk extends JInternalFrame implements ActionListener {
TextField txtPanjang, txtLebar, txtHasil,txttinggi,txtrms;
Button btnHitung,btnReset,btnSimpan;
Label lblPanjang, lblLebar, lblHasil,lbltinggi,lblrms;
double hasil;
DefaultListModel lmodel;
JList list = new JList();
public luasblk(){
super("Luas balok",true,true,true,true);
Icon h = null;
try {
h = new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/balok.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
setFrameIcon(h);
Panel panelhasan = new Panel();
Panel panelbasri = new Panel();
Panel panelhb = new Panel();
lmodel = new DefaultListModel();
list = new JList(lmodel);
JScrollPane scroll = new JScrollPane(list);
scroll.setBounds(30,40,50,20);
this.add(scroll);
panelhasan.setLayout(new GridLayout(7, 1));
panelhasan.add(lblPanjang = new Label("Panjang: "));
panelhasan.add(lblLebar = new Label("Lebar: "));
panelhasan.add(lbltinggi = new Label("tinggi: "));
panelhasan.add(new Label());
panelhasan.add(lblHasil = new Label("Volume: "));
panelhasan.add(lblrms = new Label("RUMUS: "));
panelbasri.setLayout(new GridLayout(7, 1));
panelbasri.add(txtPanjang = new TextField(""));
panelbasri.add(txtLebar = new TextField());
panelbasri.add(txttinggi = new TextField());
panelbasri.add(btnHitung = new Button("Hitung"));
btnHitung.setBackground(Color.red);
panelbasri.add(txtHasil = new TextField());
panelbasri.add(txtrms = new TextField("2*(P*L+L*T+P*T)"));
panelhb.setLayout(new GridLayout(4, 1));
panelhb.add(btnReset=new Button("Reset"));
btnReset.setBackground(Color.red);
panelhb.add(btnSimpan=new Button("Simpan"));
btnSimpan.setBackground(Color.red);
panelhb.add(scroll);
getContentPane().setBackground(Color.red);
btnHitung.addActionListener(this);
btnSimpan.addActionListener(this);
btnReset.addActionListener(this);
add(panelhasan, BorderLayout.WEST);
add(panelbasri, BorderLayout.CENTER);
add(panelhb, BorderLayout.EAST);
setSize(500,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(btnHitung)) {
hasil = 2 * (Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txtLebar.getText())
+Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txttinggi.getText())+
Double.parseDouble(txttinggi.getText()) * Double.parseDouble(txtLebar.getText()));
txtHasil.setText(""+hasil);
}else if(e.getSource() == btnSimpan){
lmodel.addElement("Panjang :" + txtPanjang.getText());
lmodel.addElement("Lebar :" + txtLebar.getText());
lmodel.addElement("tinggi :" + txttinggi.getText());
lmodel.addElement("Luas Balok :" + txtHasil.getText());
}else if(e.getSource() == btnReset){
txtPanjang.setText(" ");
txtLebar.setText(" ");
txttinggi.setText(" ");
txtHasil.setText(" ");
}else {
this.dispose();
}
}
}
INTERNAL FRAME VOLUME BALOK
import java.awt.*;
import java.awt.event.*;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class vlmeblk extends JInternalFrame implements ActionListener {
TextField txtPanjang, txtLebar, txtHasil,txttinggi,txtrms;
Button btnHitung,btnReset,btnSimpan;
Label lblPanjang, lblLebar, lblHasil,lbltinggi,lblrms;
double hasil;
DefaultListModel lmodel;
JList list = new JList();
public vlmeblk(){
super("volume balok",true,true,true,true);
Icon h = null;
try {
h = new javax.swing.ImageIcon(getClass().getResource("/hitungbngun/balok.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
setFrameIcon(h);
Panel panelhasan = new Panel();
Panel panelbasri = new Panel();
Panel panelhb = new Panel();
lmodel = new DefaultListModel();
list = new JList(lmodel);
JScrollPane scroll = new JScrollPane(list);
scroll.setBounds(30,40,50,20);
this.add(scroll);
panelhasan.setLayout(new GridLayout(7, 1));
panelhasan.add(lblPanjang = new Label("Panjang: "));
panelhasan.add(lblLebar = new Label("Lebar: "));
panelhasan.add(lbltinggi = new Label("tinggi: "));
panelhasan.add(new Label());
panelhasan.add(lblHasil = new Label("Volume: "));
panelhasan.add(lblrms = new Label("RUMUS: "));
panelbasri.setLayout(new GridLayout(7, 1));
panelbasri.add(txtPanjang = new TextField(""));
panelbasri.add(txtLebar = new TextField());
panelbasri.add(txttinggi = new TextField());
panelbasri.add(btnHitung = new Button("Hitung"));
btnHitung.setBackground(Color.red);
panelbasri.add(txtHasil = new TextField());
panelbasri.add(txtrms = new TextField("panjang*lebar*tinggi"));
panelhb.setLayout(new GridLayout(4, 1));
panelhb.add(btnReset=new Button("Reset"));
btnReset.setBackground(Color.red);
panelhb.add(btnSimpan=new Button("Simpan"));
btnSimpan.setBackground(Color.red);
panelhb.add(scroll);
getContentPane().setBackground(Color.red);
btnHitung.addActionListener(this);
btnSimpan.addActionListener(this);
btnReset.addActionListener(this);
add(panelhasan, BorderLayout.WEST);
add(panelbasri, BorderLayout.CENTER);
add(panelhb, BorderLayout.EAST);
setSize(500,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(btnHitung)) {
hasil = Double.parseDouble(txtPanjang.getText()) * Double.parseDouble(txtLebar.getText()) *
Double.parseDouble(txttinggi.getText());
txtHasil.setText(""+hasil);
}else if(e.getSource() == btnSimpan){
lmodel.addElement("Panjang :" + txtPanjang.getText());
lmodel.addElement("Lebar :" + txtLebar.getText());
lmodel.addElement("tinggi :" + txttinggi.getText());
lmodel.addElement("Volume Balok :" + txtHasil.getText());
}else if(e.getSource() == btnReset){
txtPanjang.setText(" ");
txtLebar.setText(" ");
txttinggi.setText(" ");
txtHasil.setText(" ");
}else {
this.dispose();
}
}
}
selanjutnya buat internal frame luas dan volume kubus,luas dan volume kerucut,luas dan volume bola dll..
untuk lebih jelas download saja projeknya DISINI
adapun hasinya seperti ini