User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,578 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1218 | Replies: 1
Reply
Join Date: Nov 2007
Posts: 6
Reputation: inflex is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
inflex inflex is offline Offline
Newbie Poster

TexField change Integer Also Combobox

  #1  
Nov 12th, 2007
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");

	}
	}

	}
}
	
	
	
	
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: TexField change Integer Also Combobox

  #2  
Nov 13th, 2007
those errors aren't generated on that line. Find out the lines with the problems (the compiler gives you the line numbers even...) and fix them.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 8:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC