Hi Everybody,
I wrote below codes which check textfiled and comco box for equals. But i want write a integer in textfiled and check it with combobox;
For example
When i write in texfiled 10 in the 10. on combobox is Balıkesir so if i select Balıkesir it's true but another it's false like that
Also i try this but notthing work.
String te;
te = tf.getText();
int te2 = Integer.parseInt(te);
give me an error like this
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from int to boolean
Type mismatch: cannot convert from String to int
Can you help me for this Subject. And sorry for my English.
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class source extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
String plaka[] = {
"Adana", "Adıyaman", "Afyon", "Ağrı", "Amasya", "Ankara", "Antalya","Artvin", "Aydın", "Balıkesir", "Bilecik", "Bingöl", "Bitlis", "Bolu",
"Bolu", "Burdur", "Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli","Diyarbakır", "Edirne", "Elazığ", "Erzincan", "Erzurum", "Eskişehir", "Gaziantep",
"Giresun", "Gümüşhane", "Hakkari", "Hatay", "Isparta", "İçel", "İstanbul","İzmir", "Kars", "Kastamonu", "Kayseri", "Kırklareli", "Kırşehir", "Kocaeli",
"Kütahya", "Malatya", "Manisa", "Kahramanmaraş", "Mardin", "Muğla", "Muş","Nevşehir", "Niğde", "Ordu", "Rize", "Sakarya", "Samsun", "Siirt",
"Sinop", "Sivas", "Tekirdağ", "Tokat", "Trabzon", "Tunceli", "Şanlıurfa","Uşak", "Van", "Yozgat", "Zonguldak", "Aksaray", "Bayburt", "Karaman",
"Kırıkkale", "Batman", "Şırnak", "Bartın", "Ardahan", "Iğdır", "Yalova","Karabük", "Kilis", "Osmaniye", "Düzce"
};
JComboBox plakaCB = new JComboBox(plaka);
JTextField tf = new JTextField(23);
public static void main(String[] args) { // main
source ar = new source();
}
public source(){ // Constructor
JScrollPane tf1 = new JScrollPane( tf );
JButton showB = new JButton("Kontrol");
showB.addActionListener( new BtnListener() );
JPanel content = new JPanel( new FlowLayout() );
content.add( tf1 );
content.add( plakaCB);
content.add(showB);
setContentPane( content );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setVisible(true);
pack();
}
class BtnListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
int index = plakaCB.getSelectedIndex();
if (plakaCB.getItemAt(index).equals(tf.getText())) {
JOptionPane.showMessageDialog(null, "True");
}
else{
JOptionPane.showMessageDialog(null, "wrong");
}
}
}
}