MrSvennie93
Gebruiker
- Lid geworden
- 23 sep 2011
- Berichten
- 101
Hallo,
Ik heb de volgende code:
Het probleem is dat hij vast loopt wanneer ik op de button overzicht klik. Wie helpt mij?
Mvg,
Sven
Ik heb de volgende code:
Code:
package modelbouw;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class OnderdelenOverzichtFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JPanel titelpanel, gegevenspanel, navigatiepanel;
private JLabel titel;
private JButton terug, overzicht;
private JLabel lblLocatie;
private JComboBox<?> locatie;
@SuppressWarnings({ "unchecked", "rawtypes" })
public OnderdelenOverzichtFrame() {
setLayout(new BorderLayout());
Font f = new Font("Courier New", Font.BOLD, 30);
GridLayout gl = new GridLayout(5,2,20,10);
EmptyBorder eb = new EmptyBorder(50, 30, 0, 0);
/* Titel */
titelpanel = new JPanel();
add(titelpanel, BorderLayout.NORTH);
titel = new JLabel("Onderdelen");
titel.setFont(f);
titelpanel.add(titel);
/* GEGEVENS INVOER */
gegevenspanel = new JPanel();
add(gegevenspanel, BorderLayout.CENTER);
gegevenspanel.setLayout(gl);
gegevenspanel.setBorder(eb);
lblLocatie = new JLabel("Locatie");
gegevenspanel.add(lblLocatie);
String[] locaties = { "1-1", "1-2", "1-3", "1-4", "1-5", "2-1", "2-2", "2-3", "2-4", "2-5", "3-1", "3-2", "3-3", "3-4", "3-5", "4-1", "4-2", "4-3", "4-4", "4-5", "5-1", "5-2", "5-3", "5-4", "5-5", "6-1", "6-2", "6-3", "6-4", "6-5", "7-1", "7-2", "7-3", "7-4", "7-5", "8-1", "8-2", "8-3", "8-4", "8-5", "9-1", "9-2", "9-3", "9-4", "9-5", "10-1", "10-2", "10-3", "10-4", "10-5", "11-1", "11-2", "11-3", "11-4", "11-5", "12-1", "12-2", "12-3", "12-4", "12-5",};
locatie = new JComboBox(locaties);
gegevenspanel.add(locatie);
/* NAVIGATIEPANEL */
navigatiepanel = new JPanel();
add(navigatiepanel, BorderLayout.SOUTH);
navigatiepanel.setLayout(new BorderLayout());
terug = new JButton("Ga terug");
terug.addActionListener(this);
navigatiepanel.add(terug, BorderLayout.WEST);
overzicht = new JButton("Toon overzicht");
overzicht.addActionListener(this);
navigatiepanel.add(overzicht);
setSize(800,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == terug)
{
HoofdFrame hf = new HoofdFrame();
hf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.dispose();
}
if(ae.getSource() == overzicht)
{
String iLocatie = locatie.getSelectedItem().toString();
try
{
String filename = "C:\\Users\\Sven\\Documents\\App directories\\Eclipse\\ModelbouwJava\\src\\modelbouw\\" + iLocatie + ".txt";
File f = new File(filename);
if(f.exists())
{
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String regel = br.readLine();
Scanner sc = new Scanner(regel);
int aantal = 0;
sc.useDelimiter("\\s*||\\s*");
while(sc.hasNext())
{
aantal++;
}
System.out.println(aantal);
br.close();
}
else
{
}
}
catch (Exception e)
{
}
}
}
public void onSelectedItemChanged() {
}
}
Het probleem is dat hij vast loopt wanneer ik op de button overzicht klik. Wie helpt mij?
Mvg,
Sven