G
Guest
Gast
Hi,
ich hab eine Datei in der folgende Daten enthält!
Hab diese Datei Zeilenweise ausgelesen und in einer verketteten Liste gespeichert. Ich hätte gern für jede Zeile einen eigenen JRadioButton.
Kann mir jemand helfen?
ich hab eine Datei in der folgende Daten enthält!
Code:
Instance0 host:port
Instance1 host:port
Instance2 host:port
Instance3 host:port
Hab diese Datei Zeilenweise ausgelesen und in einer verketteten Liste gespeichert. Ich hätte gern für jede Zeile einen eigenen JRadioButton.
Kann mir jemand helfen?
Code:
package instance;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Properties;
public class GUIInstance extends JDialog implements ActionListener{
public GUIInstance(){
loadInstances();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( ((d.width - getSize().width ) / 3)+50,((d.height - getSize().height) / 3)+50);
setTitle("Chooce Instance");
setModal(true);
setResizable(false);
getContentPane().setLayout(new BorderLayout());
textarea = new JPanel();
textarea.setLayout(new BorderLayout());
textarea.setBorder(BorderFactory.createTitledBorder("Instance"));
text=new JLabel("Please mark Instance to analyze:");
textarea.add(text,BorderLayout.NORTH);
opt1 = new JRadioButton("blaa",true);
opt2 = new JRadioButton("blubb",false);
group= new ButtonGroup();
group.add(opt1);
group.add(opt2);
textarea.add(opt1,BorderLayout.CENTER);
textarea.add(opt2,BorderLayout.SOUTH);
buttonarea = new JPanel();
ok = new JButton("OK");
buttonarea.add(ok);
ok.addActionListener(this);
getContentPane().add(textarea, BorderLayout.NORTH);
getContentPane().add(buttonarea, BorderLayout.SOUTH);
pack();
show();
}
public void actionPerformed(ActionEvent e){
if(opt1.isSelected()){
instanceid=1;
instance=opt1.getText();
}
if(opt2.isSelected()){
instanceid=2;
instance=opt2.getText();
}
setVisible(false);
return;
}
public int getInstanceID(){
return instanceid;
}
public String getInstanceName(){
return instance;
}
public void loadInstances(){
try
{
FileReader fReader = new FileReader(path+"//instance/instance.ini");
BufferedReader bReader = new BufferedReader(fReader);
instancelist=new LinkedList();
String lineread;
while((lineread=bReader.readLine())!=null){
System.out.println(lineread);
instancelist.add(lineread);
}
bReader.close();
}catch(IOException e){e.printStackTrace();}
}
private JPanel buttonarea;
private JButton ok;
private JPanel textarea;
private JLabel text;
private ButtonGroup group;
private JRadioButton opt1;
private JRadioButton opt2;
private String instance="";
private LinkedList instancelist;
private int instanceid;
private String path = System.getProperty("user.dir");
public static void main(String[] args) {
GUIInstance test = new GUIInstance();
}
}