Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

choice - or combo

Status
Not open for further replies.

NNNNN

MIS
Dec 2, 2002
90
GB
hello

Can a combobox be added to an applet please?

is it choice() or jcombobox()

and what would I need to import

import java. ?

thanks
 
// here are my example for jframe, you need to import the following
import java.applet.*; // for applet
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mycom extends JFrame implements ActionListener
{
String nameList[] = {"Adam","Bob"};
JComboBox selectName;
JCheckBox checkName[];
public mycom()
{
super("JComboBox and checkbox");
selectName = new JComboBox(nameList);
checkName = new JCheckBox[20];
getContentPane().setLayout(new GridLayout(21,1));
getContentPane().add(selectName);
selectName.addActionListener(this);
for (int i=0;i<nameList.length;i++)
{
checkName = new JCheckBox(nameList);
getContentPane().add(checkName);
}
}
public void actionPerformed(ActionEvent e)
{
System.out.println(selectName.getSelectedIndex());
if (selectName.getSelectedIndex()!=-1)
{
for (int i=0;i<nameList.length;i++)
{
checkName.setSelected(false);
}
checkName[selectName.getSelectedIndex()].setSelected(true);
}
}
public static void main(String args[])
{
mycom mycomObj = new mycom();
mycomObj.setSize(400,400);
mycomObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mycomObj.setVisible(true);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top