Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class yang pertama
- package com.odeng.view;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- public class Main extends javax.swing.JFrame {
- private final String userName = "odeng";
- private final String pswd = "admin";
- /** Creates new form Main */
- public Main() {
- initComponents();
- setLocationRelativeTo(null);
- }
- public JTextField getTextUsername() {
- return jTextField1;
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jdLogin = new javax.swing.JDialog();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jPasswordField1 = new javax.swing.JPasswordField();
- jButton2 = new javax.swing.JButton();
- jButton1 = new javax.swing.JButton();
- jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
- jLabel1.setText("Username: ");
- jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
- jLabel2.setText("Password:");
- jButton2.setText("Ok");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jdLoginLayout = new javax.swing.GroupLayout(jdLogin.getContentPane());
- jdLogin.getContentPane().setLayout(jdLoginLayout);
- jdLoginLayout.setHorizontalGroup(
- jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jdLoginLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jPasswordField1)
- .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
- .addContainerGap(13, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdLoginLayout.createSequentialGroup()
- .addContainerGap(145, Short.MAX_VALUE)
- .addComponent(jButton2)
- .addContainerGap())
- );
- jdLoginLayout.setVerticalGroup(
- jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jdLoginLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jdLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2)
- .addContainerGap(14, Short.MAX_VALUE))
- );
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("Login");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton1)
- .addContainerGap(333, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton1)
- .addContainerGap(266, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- jdLogin.setVisible(true);
- jdLogin.setLocationRelativeTo(null);
- jdLogin.setSize(200, 100);
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if(jTextField1.getText().equalsIgnoreCase(userName) &&
- String.valueOf(jPasswordField1.getPassword()).equalsIgnoreCase(pswd)){
- jdLogin.setVisible(false);
- JOptionPane.showMessageDialog(this, "Anda berhasil login");
- new Isian().setVisible(true);
- } else{
- JOptionPane.showMessageDialog(this, "Anda gagal login");
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Main().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JPasswordField jPasswordField1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JDialog jdLogin;
- // End of variables declaration
- }
- //class yang kedua
- package com.odeng.view;
- public class Isian extends javax.swing.JFrame {
- /** Creates new form Isian */
- public Isian() {
- initComponents();
- setTextField();
- }
- private void setTextField(){
- Main m = new Main();
- textGanti.setText(m.getTextUsername().getText());
- System.out.println("ambil: "+m.getTextUsername().getText());
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- textGanti = new javax.swing.JTextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("yang login:");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1)
- .addGap(18, 18, 18)
- .addComponent(textGanti, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(textGanti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Isian().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JTextField textGanti;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement