
Write an applet program to transfer the content of the text field into the listbox component on clicking a button code project

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class AddValueToList extends JFrame {
JList list;
DefaultListModel model;
public AddValueToList() {
setLayout(new BorderLayout());
model = new DefaultListModel();
list = new JList(model);
model.addElement("C/C++");
model.addElement("Java");
model.addElement("Perl");
model.addElement("Pascal");
JLabel lab=new JLabel("Enter Programming Language: ");
final JTextField text=new JTextField(20);
JScrollPane pane = new JScrollPane(list);
JButton addButton = new JButton("Add Element");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String lang=text.getText();
model.addElement(lang);
}
});
setLayout(null);
lab.setBounds(10,10,200,20);
text.setBounds(210,10,150,20);
addButton.setBounds(210,40,120,20);
pane.setBounds(370,10,100,100);
add(lab);
add(text);
add(addButton);
add(pane);
setVisible(true);
setSize(500,250);
}
public static void main(String s[]) {
new AddValueToList();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.