Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jp_3;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.FlowLayout;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.concurrent.TimeUnit;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- public class MyFrame extends JFrame {
- private String user = "dominika";
- private char[] pass = {'1','2','3','4','5'};
- JTextField login = new JTextField("",15);
- JPasswordField haslo = new JPasswordField("",15);
- JLabel loginLabel = new JLabel("Login:");
- JLabel hasloLabel = new JLabel("Haslo:");
- JPanel p = new JPanel(new GridBagLayout());
- Container cp = getContentPane();
- int licznik = 0;
- public MyFrame()
- {
- super("Logowanie");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- GridBagConstraints px = new GridBagConstraints();
- setSize(220, 160);
- setLocation(50,50);
- setLayout(new FlowLayout());
- px.fill = GridBagConstraints.HORIZONTAL;
- px.gridx = 0;
- px.gridy = 0;
- p.add(loginLabel, px);
- px.fill = GridBagConstraints.HORIZONTAL;
- px.gridx = 0;
- px.gridy = 1;
- p.add(login, px);
- px.fill = GridBagConstraints.HORIZONTAL;
- px.gridx = 0;
- px.gridy = 2;
- p.add(hasloLabel, px);
- px.fill = GridBagConstraints.HORIZONTAL;
- px.gridx = 0;
- px.gridy = 3;
- p.add(haslo, px);
- add(p);
- //add(new JButton("Ok"));
- OkButton Ok = new OkButton();
- add(Ok);
- AnulujButton Anuluj = new AnulujButton();
- add(Anuluj);
- Ok.addActionListener( new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- /* if(s == "abcd") {
- //System.out.print("dobrze");
- p.setBackground(Color.GREEN);
- cp.setBackground(Color.GREEN);
- }
- else {
- //System.out.print("zle\n");
- p.setBackground(Color.RED);
- cp.setBackground(Color.RED);
- }*/
- if( (login.getText() == user) && (haslo.getPassword() == pass) ) {
- //System.out.print("dobrze");
- p.setBackground(Color.GREEN);
- cp.setBackground(Color.GREEN);
- }
- else {
- //System.out.print("zle\n");
- //System.out.print(username.getText());
- p.setBackground(Color.RED);
- cp.setBackground(Color.RED);
- }
- }
- });
- setVisible(true);
- }
- class OkButton extends JButton {
- OkButton() {
- super("Ok");
- //addActionListener(this);
- }
- //@Override
- /*public void actionPerformed(ActionEvent e) {
- licznik++;
- if (licznik < 3)
- {
- p.setBackground(Color.GREEN);
- cp.setBackground(Color.GREEN);
- }
- else
- {
- p.setBackground(Color.RED);
- cp.setBackground(Color.RED);
- licznik = 0;
- }
- }*/
- }
- class AnulujButton extends JButton //implements ActionListener
- {
- AnulujButton() {
- super("Anuluj");
- // addActionListener(this);
- }
- /*@Override
- public void actionPerformed(ActionEvent e) {
- licznik++;
- if (licznik < 3)
- {
- p.setBackground(Color.GREEN);
- cp.setBackground(Color.GREEN);
- }
- else
- {
- p.setBackground(Color.RED);
- cp.setBackground(Color.RED);
- licznik = 0;
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement