Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

data types not matching......

 
mayank yadav
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi....in the given codes
after compiling iam getting an error
data types not matching.....
please help me to correct it...

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button.*;

public class List extends JFrame
{
public String s;
JFrame f;
JPanel po;
JComboBox cb;
JTextField tf;


public static void main (String arg[])
{

List obj = new List();
}


public List()
{


f = new JFrame("list");
po= new JPanel();
tf= new JTextField(30);
f.getContentPane().add(po);
f.setVisible(true);
f.setSize(300,300);
String[] hos = {"Hostel1","Hostel2","Hostel3","hostel4","hostel6"};
cb = new JComboBox(hos);
cb.setMaximumRowCount(3);
//cb.addItemListener(this);
po.add(cb);
po.add(tf);
process();



}

public void process()
{
s= hos[cb.getSelectedItem()];
tf.setText(s);

}
}
 
Mark Van Tuyl
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You need to pass the array of Strings (hos) to the process method.
You need an integer as an index into the array, so you should use getSelectedIndex instead of getSelectedItem.
 
Mark Van Tuyl
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A better option would be:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!