import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.event.*; public class VitseApp { public static void main(String[] args){ JFrame vindu = new JFrame("VitseVindu"); vindu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFileChooser fileChooser = new JFileChooser(); int resultat = fileChooser.showOpenDialog(null); ArrayList vitser=null; if (resultat == JFileChooser.APPROVE_OPTION){ File fil = fileChooser.getSelectedFile(); try{ vitser = lagVitser(fil); }catch(FileNotFoundException e){ System.exit(1); } }else{ System.exit(1); } // objekt 1, er en String med punchline //objekt 2, er en label ? putte den i. class Trykkbehandler implements ActionListener{ String punchline; JLabel label; public Trykkbehandler(String punchline, JLabel label){ this.punchline = punchline; this.label = label; } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub settPunchline(label, punchline); } } JPanel panel = new JPanel(); JButton knapp = new JButton(); JLabel punchline = new JLabel("*drumroll*"); knapp.addActionListener(new Trykkbehandler(vitser.get(1).getPunchline(),punchline )); JLabel setup = new JLabel(vitser.get(1).getSetup()); panel.add(knapp); panel.add(setup); panel.add(punchline); vindu.add(panel); vindu.setVisible(true); vindu.pack(); } static public ArrayList lagVitser(File fil) throws FileNotFoundException{ Scanner minScanner = new Scanner(fil); ArrayList mineVitser = new ArrayList<>(); while (minScanner.hasNextLine()){ String vits = minScanner.nextLine(); String[] biter = vits.split(";"); mineVitser.add(new Vits(biter[0], biter[1])); } minScanner.close(); return mineVitser; } public static void settPunchline(JLabel label, String punchline){ label.setText(punchline); } } class Vits{ private String setup; private String punchline; public Vits(String s, String p){ setup = s; punchline = p; } public String getSetup() { return setup; } public String getPunchline() { return punchline; } }