Java Reference
In-Depth Information
// Set up buttons
JPanel jp = new JPanel(new GridLayout(2, 1));
JPanel jp1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 1, 1));
JPanel jp2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 1, 1));
jp.add(jp1);
jp.add(jp2);
JButton jb = new JButton("add F");
jp1.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
model.add(0, "First");
}
});
jb = new JButton("addElement L");
jp1.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
model.addElement("Last");
}
});
jb = new JButton("insertElementAt M");
jp1.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int size = model.getSize();
model.insertElementAt("Middle", size/2);
}
});
jb = new JButton("set F");
jp1.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int size = model.getSize();
if (size != 0)
model.set(0, "New First");
}
});
jb = new JButton("setElementAt L");
jp1.add(jb);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int size = model.getSize();
if (size != 0)
model.setElementAt("New Last", size-1);
}
});
Search WWH ::




Custom Search