Thursday, June 27, 2013

CONTOH PEMROGRAMAN JAVA LOOPING DAN LOGIN

Di bawah ini adalah contoh looping dan Login pemrograman java :
1. Looping



public class Looping {
    public static void main (String[] args) {
        int i;
        int j;
        for (i=1;i<=1;i++)    {
            for (j=1;j<=0;j++)    {
                System.out.print("100");
            }
            System.out.println("100");
        }
        for (i=1;i<=1;i++)    {
            for (j=1;j<=1;j++)    {
                System.out.print("80");
            }
            System.out.println("80");
        }
        for (i=1;i<=1;i++)    {
            for (j=1;j<=2;j++)    {
                System.out.print("60");
            }
            System.out.println("60");
        }for (i=1;i<=1;i++)    {
            for (j=1;j<=3;j++)    {
                System.out.print("40");
            }
            System.out.println("40");
        }
        for (i=1;i<=1;i++)    {
            for (j=1;j<=4;j++)    {
                System.out.print("20");
            }
            System.out.println("20");
        }
        for (i=1;i<=1;i++)    {
            for (j=1;j<=5;j++)    {
                System.out.print("10");
            }
            System.out.println("10");
        }
    }
}


2. Login

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

public class SimpleLogin extends JFrame implements ActionListener {
private JLabel label1, label2;
private JTextField txtUser;
private JPasswordField pwdPass;
private JButton btnLogin, btnExit;

public SimpleLogin() {
super ("Login here...");

Container container = getContentPane();
container.setLayout(new FlowLayout());

label1 = new JLabel ("Username : ");
label2 = new JLabel ("Password : ");

txtUser = new JTextField (20);
txtUser.setToolTipText("Input Username");
pwdPass = new JPasswordField(20);

btnLogin = new JButton ("Login");
btnLogin.addActionListener(this);
btnExit = new JButton ("Exit");
btnExit.addActionListener(this);

container.add(label1);
container.add(txtUser);
container.add(label2);
container.add(pwdPass);
container.add(btnLogin);
container.add(btnExit);

setSize (300,200);
setVisible (true);
}

public static void main (String args[]) {
SimpleLogin test = new SimpleLogin();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

test.setLocation(350,250);
test.setResizable(false);
test.show();
}

private String user = "", pass = "";
public void actionPerformed (ActionEvent e) {
if (e.getSource() == btnLogin) {
user = txtUser.getText();
pass = pwdPass.getText();
if (user.equals("Sudiono") && pass.equals("1234")) {
JOptionPane.showMessageDialog(null, "Login successfull");
} else {
JOptionPane.showMessageDialog(null, "anda tidak berhak mengakses program ini!");
txtUser.setText("");
pwdPass.setText("");
txtUser.requestFocus(true);
}
} else if (e.getSource() == btnExit){
JOptionPane.showMessageDialog(null,"Thanks to try my program. See you..");
System.exit(0);
}
}
}

0 comments:

Post a Comment

 
Free Flash TemplatesRiad In FezFree joomla templatesAgence Web MarocMusic Videos OnlineFree Website templateswww.seodesign.usFree Wordpress Themeswww.freethemes4all.comFree Blog TemplatesLast NewsFree CMS TemplatesFree CSS TemplatesSoccer Videos OnlineFree Wordpress ThemesFree CSS Templates Dreamweaver