Kamis, 27 November 2008

Java Text Reader

Some weeks ago i got assignment from my lecturer to create this program. Actually i dont have any idea how to make it. Blank in my head --"
since i just learn Java a week before the assignment came, so I'm totally newbie about Java. And what? He gives me this project..

(image will be loaded soon, i'm having little time to write this entry ^^')

And finally H-1 before the assignment deadline, my friend gave me this code, I dunno where do he got it. (Finally i knwo It is Justian the man behind this code, thx dude!) Here is the code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class MyApp extends JFrame{
private JPanel pnlAtas = new JPanel(new FlowLayout(FlowLayout.CENTER)),
pnlTgh = new JPanel(new BorderLayout()),
pnlBawah= new JPanel(new FlowLayout(FlowLayout.CENTER));

private JLabel lblLogo = new JLabel(new ImageIcon("bee.jpg"));

private JButton btnSimpan = new JButton("Simpan"),
btnBaca = new JButton("Baca"),
btnKeluar = new JButton("Keluar");

private JTextArea txt = new JTextArea();
private JScrollPane spTxt = new JScrollPane(txt);

public MyApp(){
super("Aplikasi Input Output");
setSize(400,300);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);

init();
setLayout();
}

public String getTxt(){
return txt.getText();
}
public void setTxt(String s){
txt.setText(s);
}

private void init(){
btnSimpan.setMnemonic('S');
btnSimpan.addActionListener(new ButtonHandler(this));
btnBaca.setMnemonic('B');
btnBaca.addActionListener(new ButtonHandler(this));
btnKeluar.setMnemonic('e');
btnKeluar.addActionListener(new ButtonHandler(this));
}

private void setLayout(){
pnlAtas.add(lblLogo);
pnlTgh.add(spTxt,"Center");
pnlBawah.add(btnSimpan);
pnlBawah.add(btnBaca);
pnlBawah.add(btnKeluar);

getContentPane().add(pnlAtas,"North");
getContentPane().add(pnlTgh,"Center");
getContentPane().add(pnlBawah,"South");
}

public static void main(String[] args){
new MyApp().setVisible(true);
}
}

Function are written in Bahasa, not difficult to understand i think.
May help you guys understand Java

Tidak ada komentar: