Monday, January 24, 2011

preparing for java programming lab test .

here i am, steal some minutes after learns the java programming subject..
fiuhh, my head's heavy and dizzy but lazy in the same time when i try to remember all the things about java's coding.. fiuhh~ :')
actually i'm not really good at coding, i'm just good at design-ing with html.
and not really good to handle or make a really great programs through with java, vb.net, php or such as like them.. mine was so so... (@@')a
it's hendy's job! my job's only about design-ing, analyst and business!! hahaha. :DD

heyy yaa, i dunno whether you've know what major that i takes or not.
fyi, currently i'm taking Information System at Binus University, Jakarta, Indonesia. :)
anyway, if you don't mind i'm gonna spoil your monitor with these all java's codings, all was typed by myself through eclipse sdk 3.3.1 that's installed into my lappie... hehehe. :DD
*beware, maybe these all will make your head heavy as much as mine or maybe heavier than mine.. opps, sorry... (^^ ,)v

Menu.java
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.sun.org.apache.xerces.internal.impl.dtd.models.CMBinOp;


public class Menu extends JFrame implements ActionListener{
JButton btn1 = new JButton("Ok");
JButton btn2 = new JButton("Cancel");
JLabel lbl1 = new JLabel("Login Form");
JLabel lbl2 = new JLabel("Username");
JLabel lbl3 = new JLabel("Password");
JTextField txt1 = new JTextField();
JPasswordField pass1 = new JPasswordField();
//JList list1 = new JList();
JPanel pan1 = new JPanel(new FlowLayout());
JPanel pan2 = new JPanel(new GridLayout(3,2));
//JPanel pan3 = new JPanel(new BorderLayout());
JPanel pan3 = new JPanel(new FlowLayout());
public Menu() //constructor, semua program dijalankan disini..
{
setTitle("Menu");
add(pan1,"North");
add(pan2,"Center");
add(pan3,"South");
pan1.add(lbl1);
pan2.add(lbl2);
pan2.add(txt1);
pan2.add(lbl3);
pan2.add(pass1);
//pan2.add(list1);
pan3.add(btn1);
pan3.add(btn2);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//pack();
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public static void main(String[] args) {
new Menu();

}

//FileWriter...
private void InputData()
{
String BabyMilo;
BabyMilo = txt1.getText() + ";" + pass1.getText();
try{
PrintWriter Mickey = new PrintWriter(new FileWriter("Data.txt",true));
Mickey.println(BabyMilo);
Mickey.close();
}catch (Exception e) {
e.printStackTrace();
}
}
//FileReader...
private void ReadData(){
int p = 0;
String Doraemon[];
try{
BufferedReader Minnie = new BufferedReader(new FileReader("Data.txt"));
Doraemon = Minnie.readLine().split(";");
for(int i=0;i
Doraemon = Minnie.readLine().split(";");
}
txt1.setText(Doraemon[0]);
pass1.setText(Doraemon[1]);
Minnie.close();
}catch (Exception e) {
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent arg0) {
Object a = arg0.getSource();
if(a == btn1)
{
if(txt1.getText().equals("") && pass1.getText().equals("") )
{
JOptionPane.showMessageDialog(this, "You must filled in the blank!");
}
else if(txt1.getText().equals(txt1.getText()) && pass1.getText().equals(pass1.getText()))
{
InputData();
//ReadData();
JOptionPane.showMessageDialog(this, "Login Succeed!");
txt1.setText("");
pass1.setText("");
new Layout();
}
}
else if(a == btn2)
{
JOptionPane.showMessageDialog(this, "Login Canceled!");
dispose();
}
}

}

Layout.java
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class Layout extends JFrame implements ActionListener{

JButton btn1 = new JButton("Ok");
JButton btn2 = new JButton("Cancel");
JLabel lbl1 = new JLabel("Layout");
JLabel lbl2 = new JLabel("Username");
JLabel lbl3 = new JLabel("Password");
JTextField txt1 = new JTextField();
JPasswordField pass1 = new JPasswordField();
//JList list1 = new JList();
JPanel pan1 = new JPanel(new FlowLayout());
JPanel pan2 = new JPanel(new GridLayout(3,2));
//JPanel pan3 = new JPanel(new BorderLayout());
JPanel pan3 = new JPanel(new FlowLayout());
public Layout()
{
setTitle("Layout");
add(pan1,"North");
add(pan2,"Center");
add(pan3,"South");
pan1.add(lbl1);
pan2.add(lbl2);
pan2.add(txt1);
pan2.add(lbl3);
pan2.add(pass1);
//pan2.add(list1);
pan3.add(btn1);
pan3.add(btn2);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
btn1.addActionListener(this);
btn2.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
Object b = arg0.getSource();
if(b == btn1)
{
if(txt1.getText().equals("") && pass1.getText().equals("") )
{
JOptionPane.showMessageDialog(this, "You must filled in the blank!");
}
else if(txt1.getText().equals(txt1.getText()) && pass1.getText().equals(pass1.getText()))
{
JOptionPane.showMessageDialog(this, "Congratulations...!! :D");
}
}
else if(b == btn2)
{
JOptionPane.showMessageDialog(this, "You've been out!");
dispose();
}
}

}

have you see? don't blame me about the 'robotics language' above..
i thought bill gates, really got a problem with his head since he was a kid till now.. XP
anyway, those only for making a very really simple programs with 2 windows that runs..
what i made, it's only for login with some duties and after its succeed, you can continue to the next 'layout' window..

ohh yaa, here are 'how this codings look' after you typed what i was did above..
i'd printscreen it all for you..
this maybe a chance for you to have a lil' knowledgement from me.. ;)

- pics of how the program's run -

and then, now i think that's enough for this time.
or some of you will mad at me because of these contaminator thing..
about me? am gonna learn about java's coding again(?) tomorrow morning...
wish me luck guys~
thanks for coming to my blog anyway... ;D

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home