import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class CelsiusConverter implements ActionListener {
JFrame converterFrame;
JComboBox menu;
JPanel converterPanel, textPanel, fieldPanel, southPanel;
JTextField server, folder, errors;
JLabel serverLabel, folderLabel, errorsLabel, infoLabel, prefixLabel;
JButton getButton, stopButton;
int count;
HttpGet get = new HttpGet();
public CelsiusConverter() {
//Create and set up the window.
converterFrame = new JFrame("Picture Downloader!");
//Create and set up the panel.
converterPanel = new JPanel();
converterPanel.setLayout(new BorderLayout());
textPanel = new JPanel();
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
fieldPanel = new JPanel();
fieldPanel.setLayout(new BoxLayout(fieldPanel, BoxLayout.Y_AXIS));
southPanel = new JPanel();
southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.Y_AXIS));
menu = new JComboBox();
String t_1 = new String("001");
String t_2 = new String("01");
String t_3 = new String("1");
menu.addItem(t_1);
menu.addItem(t_2);
menu.addItem(t_3);
converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//converterPanel.setPreferredSize(new Dimension(800, 300));
converterPanel.setBackground(Color.WHITE);
//Add the widgets.
addWidgets();
//Set the default button.
converterFrame.getRootPane().setDefaultButton(getButton);
//Add the panel to the window.
converterFrame.getContentPane().add(converterPanel, BorderLayout.CENTER);
//Display the window.
converterFrame.pack();
converterFrame.setVisible(true);
}
private void addWidgets() {
//Create widgets.
server = new JTextField("
http://", 60);
folder = new JTextField("folder", 30);
errors = new JTextField("5", 10);
getButton = new JButton("Get images...");
stopButton = new JButton("Stop ...");
serverLabel = new JLabel("Server _##_ = number ", SwingConstants.LEFT);
folderLabel = new JLabel("Folder to put images...", SwingConstants.LEFT);
errorsLabel = new JLabel("Antal fejl i træk", SwingConstants.LEFT);
infoLabel = new JLabel("Info", SwingConstants.LEFT);
prefixLabel = new JLabel("Prefix", SwingConstants.LEFT);
//Listen to events from the Convert button.
getButton.addActionListener(this);
stopButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// kald til en metode som stoppe en tråd/løkke
System.out.println("STOPP");
get.keepOn = false;
}
});
//Add the widgets to the container.
textPanel.add(serverLabel);
textPanel.add(Box.createRigidArea(new Dimension (0,5)));
textPanel.add(folderLabel);
textPanel.add(Box.createRigidArea(new Dimension (0,5)));
textPanel.add(errorsLabel);
textPanel.add(Box.createRigidArea(new Dimension (0,5)));
textPanel.add(prefixLabel);
textPanel.add(Box.createRigidArea(new Dimension (0,5)));
fieldPanel.add(server);
fieldPanel.add(folder);
fieldPanel.add(errors);
fieldPanel.add(menu);
southPanel.add(getButton);
southPanel.add(stopButton);
southPanel.add(Box.createRigidArea(new Dimension (0,10)));
southPanel.add(infoLabel);
converterPanel.add(southPanel, BorderLayout.SOUTH);
converterPanel.add(fieldPanel, BorderLayout.CENTER);
converterPanel.add(textPanel, BorderLayout.WEST);
System.out.print("...\n\n\n");
}
public void actionPerformed(ActionEvent event) {
String prefix;
int err;
count++;
prefix = (String) menu.getSelectedItem();
get.keepOn = true;
get.getFiles(server.getText(), folder.getText(), Integer.parseInt(errors.getText()), prefix);
infoLabel.setText("doing... " + server.getText());
}
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
CelsiusConverter converter = new CelsiusConverter();
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}