mardi 28 avril 2015

if Statmen fails in actionListener [duplicate]

This question already has an answer here:

so i have a problem the if statement at the end of the program seems to not respond when i type in josip in the JTextField it just doesn't react i tried writing hundreds of different combinations but it just isnt reacting i don't know where is the problem can someone please take a look at my code and tell me what is wrong

import javax.swing.JTextField;
import javax.swing.JOptionPane; 
import javax.swing.JFrame; 
import java.awt.CardLayout;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JButton; 
import javax.swing.JLabel;
import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent;
import javax.swing.SpringLayout;
import java.awt.event.*;


class start extends JFrame{




public static void main(String args[]){

final String x[]={"Josip","Johan","Lohan"};
final int xl = x.length;


//Created Obecjts
JFrame frame = new JFrame();

final JPanel p = new JPanel();
final JButton b1 = new JButton("OK");
final JTextField ime = new JTextField(15);
final JTextField pass = new JTextField(15);
final JLabel label1 = new JLabel("UpisiSvojeIme");
final JLabel label2 = new JLabel("UpisiSvojuSifru");

//Panel Layout 
p.setLayout(null);

//Frame options
frame.setVisible(true);
frame.setSize(300,150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.add(p);

//Objects added to the panel 

ime.setBounds(120,15,100,20);
p.add(ime);

label1.setBounds(10,15,150,20);
p.add(label1);



pass.setBounds(120,55,100,20);
p.add(pass);

label2.setBounds(10,55,150,20);
p.add(label2);


b1.setBounds(230,93,65,20);
 p.add(b1);


 b1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

String name = ime.getText();

System.out.println(name);

if(name == "JOSIP"){
    System.out.println("JEEEEJ");
 }



}








}

);


}
}

Aucun commentaire:

Enregistrer un commentaire