rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class CatMain extends JFrame implements ActionListener
{
JButton swap = new JButton("Add/Remove");
String[] names = new String[310];
String[] test = new String[62];
String[] teachers = new String[62];
JFrame frame = new JFrame("Creating a JList Component");
JPanel panel = new JPanel();
JList list = new JList(teachers);
JList list2 = new JList(test);
JScrollPane scroll = new JScrollPane(list);
public CatMain(String title) throws IOException
{
File file = new File("schedule.txt");
Scanner scan = new Scanner(file);
int i=0;
int q=0;
while (scan.hasNextLine())
{
{
names[i] = scan.nextLine();
}
i++;
}
for(int j=0; j < names.length;j+=5)
{
teachers[q] = names[j];
q++;
}
swap.setActionCommand("swap");
list2.setPreferredSize(new Dimension(150,400));
scroll.setPreferredSize(new Dimension(150,400));
panel.add(list2);
panel.add(swap);
panel.add(scroll);
setLayout( new FlowLayout() );
add( panel );
swap.addActionListener( this );
}
public void actionPerformed( ActionEvent evt)
{
if ( evt.getActionCommand().equals( "swap" ) )
{
String name = list.isSelected();
}
}
public static void main ( String[] args ) throws IOException
{
CatMain demo = new CatMain( "CatMain" ) ;
demo.setSize( 800, 600 );
demo.setVisible( true );
}
}