SEMOGA INI BISA BERMANFAAT
klo ada masukan silahkan beri komentar
// ini program utama
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class OutputStream {
private JDesktopPane desktop = new JDesktopPane ();
private JMenuBar menu = new JMenuBar();
private JMenuBar menuBar = new JMenuBar();
private JButton btnOpen = new JButton("Open");
public OutputStream(){
JFrame frame = new JFrame("Luas Segitiga");
btnOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Internal masuk = new Internal();
desktop.add(masuk);
masuk.setVisible(true);
}
});
btnOpen.setMnemonic('O');
frame.setJMenuBar(menu);
frame.setVisible(true);
frame.setSize(400,500);
menuBar.add(btnOpen);
desktop.setBackground(Color.gray);
frame.getContentPane().add(menuBar, BorderLayout.SOUTH);
frame.getContentPane().add(desktop, BorderLayout.CENTER);
}
public static void main(String [] args){
new OutputStream();
}
}
//ini internalnya
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Internal extends JInternalFrame{
String car = ";";
private JLabel label1 = new JLabel("Alas"),
label2 = new JLabel("Tinggi"),
label3 = new JLabel("Hasil");
private JTextField txt1 = new JTextField(),
txt2 = new JTextField(),
txt3 = new JTextField(),
txt4 = new JTextField(),
txt5 = new JTextField(),
txt6 = new JTextField();
private JButton btnClear = new JButton("Clear"),
btnHasil = new JButton("Hasil"),
btnExit = new JButton("Exit"),
btnSave = new JButton("Save"),
btnLoad = new JButton("Load");
public double Luas(double A, double T){
return (0.5*A*T);
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent e) {
java.io.File file = new java.io.File("Save.txt");
java.io.PrintWriter output = null;
try {
output = new java.io.PrintWriter(file);
} catch (FileNotFoundException ex) {
Logger.getLogger(Internal.class.getName()).log(Level.SEVERE, null, ex);
}
output.print(txt1.getText()+car);
output.print(txt2.getText()+car);
output.print(txt3.getText());
output.close();
JOptionPane.showMessageDialog(null, "Saved Successfully","Success",
JOptionPane.WARNING_MESSAGE);
}
private void btnLoadActionPerformed(java.awt.event.ActionEvent e) {
int respon2 = JOptionPane.showConfirmDialog(null, "Are You Sure ?", "Tanya Dulu...",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
java.io.File file = new java.io.File("Save.txt");
Scanner input = null;
try {
input = new Scanner(file);
}
catch (FileNotFoundException ex) {
Logger.getLogger(Internal.class.getName()).log(Level.SEVERE, null, ex);
}
input.useDelimiter(";");
while (input.hasNext())
{
String m = input.next();
String p = input.next();
String q = input.next();
txt1.setText(m);
txt2.setText(p);
txt3.setText(q);
}
input.close();
}
public Internal(){
super("Luas Segitiga",true,true,true,true);
getContentPane().setLayout(null);
label1.setBounds(30,20,100,20);
label2.setBounds(30,60,100,20);
label3.setBounds(30,100,100,20);
txt1.setBounds(100,20,100,20);
txt2.setBounds(100,60,100,20);
txt3.setBounds(100,100,100,20);
btnHasil.setBounds(110,130,70,20);
btnClear.setBounds(70,170,70,20);
btnExit.setBounds(70,200,70,20);
btnSave.setBounds(150,170,70,20);
btnLoad.setBounds(150,200,70,20);
getContentPane().add(label1);
getContentPane().add(label2);
getContentPane().add(label3);
getContentPane().add(txt1);
getContentPane().add(txt2);
getContentPane().add(txt3);
getContentPane().add(btnClear);
getContentPane().add(btnHasil);
getContentPane().add(btnExit);
getContentPane().add(btnSave);
getContentPane().add(btnLoad);
btnHasil.setMnemonic(KeyEvent.VK_H);
btnClear.setMnemonic(KeyEvent.VK_C);
btnExit.setMnemonic(KeyEvent.VK_E);
btnSave.setMnemonic(KeyEvent.VK_S);
btnLoad.setMnemonic(KeyEvent.VK_L);
btnHasil.addActionListener (new ActionListener(){
public void actionPerformed(ActionEvent e){
double A = Double.parseDouble(txt1.getText());
double T = Double.parseDouble(txt2.getText());
double luas = Luas(A,T);
txt3.setText(""+luas);
}
});
btnClear.addActionListener (new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText("");
txt2.setText("");
txt3.setText("");
}
});
btnExit.addActionListener (new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
btnSave.setText("Save");
btnSave.setFocusable(false);
btnSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
btnSaveActionPerformed(e);
}
});
btnLoad.setText("Load");
btnLoad.setFocusable(false);
btnLoad.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnLoad.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnLoad.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
btnLoadActionPerformed(e);
}
});
setVisible(true);
setSize(300,300);
}
}
ini OUTPUTnya
Rank
Banner Q
Postingan
- CSS (1)
- HTML (3)
- PEMOGRAMAN BERBASIS OBJEK (6)
- Teknologi Web (3)
Download Materi Kuliah
Link
Coment dunk !!!
Jumat, 01 Mei 2009
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar