Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.FileInputStream;
- import java.io.InputStreamReader;
- class Login extends JFrame implements ActionListener
- {
- JButton SUBMIT, IP, REGISTER;
- JPanel panel;
- JLabel label1,label2, ipaddress;
- final JTextField text1,text2;
- Font font = new Font("Arial", Font.BOLD, 15);
- String[] ips;// przez to program nie dziala
- Login()
- {
- JComboBox ipList = new JComboBox(ips);
- ipList.setSelectedIndex(1);
- ipList.setFont(font);
- ipList.addActionListener(comboBox);
- ipList.setEditable(isEnabled());
- ipaddress = new JLabel();
- ipaddress.setText("IP Address:");
- label1 = new JLabel();
- label1.setText("Username:");
- text1 = new JTextField(15);
- label2 = new JLabel();
- label2.setText("Password:");
- text2 = new JPasswordField(15);
- SUBMIT=new JButton("LOG IN");
- REGISTER=new JButton("Register");
- IP=new JButton("Add IP");
- panel=new JPanel(new GridLayout(0,1, 5, 5));
- panel.add(ipList);
- panel.add(IP);
- panel.add(label1);
- panel.add(text1);
- panel.add(label2);
- panel.add(text2);
- panel.add(SUBMIT);
- panel.add(REGISTER);
- add(panel,BorderLayout.CENTER);
- SUBMIT.addActionListener(this);
- REGISTER.addActionListener(this);
- setTitle("LOGIN FORM");
- IP.addActionListener(addIP);
- SUBMIT.addActionListener(submitForm);
- REGISTER.addActionListener(register);
- text1.addFocusListener(validation1);
- text2.addFocusListener(validation2);
- readIPS();
- }
- ActionListener comboBox = new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- JComboBox cb = (JComboBox)e.getSource();
- String petName = (String)cb.getSelectedItem();
- }
- };
- FocusListener validation1 = new FocusListener()
- {
- @Override
- public void focusGained(FocusEvent arg0) {
- text1.setBackground(Color.white);
- }
- @Override
- public void focusLost(FocusEvent arg0) {
- // TODO Auto-generated method stub
- }
- };
- FocusListener validation2 = new FocusListener()
- {
- @Override
- public void focusGained(FocusEvent arg0) {
- text2.setBackground(Color.white);
- }
- @Override
- public void focusLost(FocusEvent arg0) {
- // TODO Auto-generated method stub
- }
- };
- ActionListener submitForm = new ActionListener() {
- public void actionPerformed(ActionEvent ae)
- {
- JFrame frame = null;
- String value1=text1.getText();
- String value2=text2.getText();
- if (value1.equals("lapek") && value2.equals("lapek")) {
- AddIP page=new AddIP();
- page.setVisible(true);
- JLabel label = new JLabel("Welcome: "+value1);
- page.getContentPane().add(label);
- }
- else{
- text1.setBackground(Color.red);
- text2.setBackground(Color.red);
- JOptionPane.showMessageDialog(frame,"Enter a valid username and password");
- }
- }
- };
- ActionListener register = new ActionListener() {
- public void actionPerformed(ActionEvent ae)
- {
- System.out.println("Wpisz poprawne dane i się zarejestruj");
- Register page=new Register();
- page.setSize(400, 300);
- page.setLocationRelativeTo(null);
- page.setVisible(true);
- }
- };
- ActionListener addIP = new ActionListener() {
- public void actionPerformed(ActionEvent ae)
- {
- System.out.println("Wpisz poprawne dane i się zarejestruj");
- AddIP page = new AddIP();
- page.setSize(300, 150);
- page.setLocationRelativeTo(null);
- page.setVisible(true);
- }
- };
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- }
- public void closeWindow()
- {
- this.setVisible(false);
- }
- public static void readIPS()
- {
- try{
- FileInputStream fstream = new FileInputStream("ips.txt");
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- while ((strLine = br.readLine()) != null) {
- System.out.println (strLine);
- }
- in.close();
- }catch (Exception e){
- System.err.println("Error: " + e.getMessage());
- }
- }
- }
- class LoginDemo
- {
- public static void main(String arg[])
- {
- try
- {
- Login frame=new Login();
- frame.setSize(300,350);
- frame.setVisible(true);
- frame.setLocationRelativeTo(null);
- }
- catch(Exception e)
- {JOptionPane.showMessageDialog(null, e.getMessage());}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement