import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import javax.swing.JFrame;
public class MyGui extends javax.swing.JFrame implements ActionListener {
private static JFrame frame = null;
private ArrayList<JScrollPane> scrollPaneList = new ArrayList<JScrollPane>();
private ArrayList<JPanel> panelList = new ArrayList<JPanel>();
private ArrayList<JTable> ergebnisTabelle = new ArrayList<JTable>();
private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);
private static JCheckBox checkBoxAutoStart = new JCheckBox("mit Windows starten (SysTray)");
private Image icon = Toolkit.getDefaultToolkit().getImage("unbenannt.gif");
public MyGui() {
// Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
frame.setIconImage(icon);
//SystemTray
if (SystemTray.isSupported()) {
SystemTray sysTray = SystemTray.getSystemTray();
//create popupmenu
PopupMenu menu = new PopupMenu();
//create item
MenuItem open = new MenuItem("Öffnen");
menu.add(open);
//add action listener to the item in the popup menu
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setVisible(true);
WriteProperties.write();
}
});
//create item
MenuItem exit = new MenuItem("Beenden");
//add item to menu
menu.add(exit);
//add action listener to the item in the popup menu
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
WriteProperties.write();
System.exit(0);
}
});
//create system tray icon.
TrayIcon trayIcon = new TrayIcon(icon, "Stisys Ergebnis Checker", menu);
//add the tray icon to the system tray.
try {
sysTray.add(trayIcon);
}
catch(AWTException e) {
System.out.println("System Tray unsupported!");
}
}
frame = new JFrame("SEC");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
frame.setSize(500, 400);
// Benutzername Label
JLabel usernameLabel = new JLabel("Benutzername:");
usernameLabel.setBounds(10, 13, (int) usernameLabel.getPreferredSize()
.getWidth(), 10);
frame.add(usernameLabel);
// Passwort Label
JLabel passwordLabel = new JLabel("Passwort:");
passwordLabel.setBounds(110, 13, (int) passwordLabel.getPreferredSize()
.getWidth(), 10);
frame.add(passwordLabel);
//Usernamefeld
usernameField.setBounds(10, 25, 90, 20);
frame.add(usernameField);
// Passwortfeld
passwordField.setBounds(110, 25, 90, 20);
frame.add(passwordField);
//Ergebnisse holen Button hinzufügen
updateExams.setActionCommand("update");
updateExams.addActionListener(this);
updateExams.setBounds(210, 25, 150, 20);
frame.add(updateExams);
// TabbedPane hinzufügen mit leerer Übersicht
String[][] ergebnisse = { { "", "" }, { "Keine", "Ergebnisse" } };
String[] columnNames = { "Kurs", "Note" };
ergebnisTabelle.add(new JTable(ergebnisse, columnNames));
ergebnisTabelle.get(0).setPreferredScrollableViewportSize(
new Dimension(390, 160));
scrollPaneList.add(new JScrollPane(ergebnisTabelle.get(0)));
scrollPaneList.get(0).setViewportView(ergebnisTabelle.get(0));
panelList.add(new JPanel());
panelList.get(0).add(scrollPaneList.get(0));
tabbedPane.addTab("Übersicht", panelList.get(0));
tabbedPane.setBounds(10, 70, 480, 200);
frame.add(tabbedPane);
//AutostartOption hinzufügen
checkBoxAutoStart.setBounds(7, 350, (int) checkBoxAutoStart
.getPreferredSize().getWidth(), 15);
checkBoxAutoStart.setActionCommand("autostart");
checkBoxAutoStart.addActionListener(this);
frame.add(checkBoxAutoStart);
JButton sysTray = new JButton("in SysTray minimieren");
sysTray.setActionCommand("systray");
sysTray.addActionListener(this);
sysTray.setBounds(320, 345, (int) sysTray.getPreferredSize()
.getWidth(), 20);
frame.add(sysTray);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
@SuppressWarnings("unused")
MyGui window = new MyGui();
}
});
}
public void actionPerformed(ActionEvent e) {
// In Systray minimieren
if ("systray".equals(e.getActionCommand())) {
frame.setVisible(false);
WriteProperties.write();
//AutostartOption
} else if ("autostart".equals(e.getActionCommand())) {
//Autostart aktivieren durch Registryeintrag
if (checkBoxAutoStart.isSelected()) {
WriteProperties.write();
try {
FileWriter fw = new FileWriter(
System.getProperty("user.dir") + "\\sec.reg");
BufferedWriter out = new BufferedWriter(fw);
out.write("Windows Registry Editor Version 5.00");
out.newLine();
out.newLine();
out.write("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]");
out.newLine();
out.newLine();
String tmp = (new File("sec.reg")).getAbsolutePath()
.toString();
tmp = tmp.replace("\\", "\\\\");
out.write("\"Stisys Ergebnis Checker\"=\"" + tmp + "\"");
System.out.println(tmp);
out.close();
fw.close();
String s = "regedit /s sec.reg";
Runtime.getRuntime().exec(s);
} catch (IOException e1) {
}
//Autostart deaktivieren
} else {
try {
FileWriter fw = new FileWriter(
System.getProperty("user.dir") + "\\sec.reg");
BufferedWriter out = new BufferedWriter(fw);
out.write("Windows Registry Editor Version 5.00");
out.newLine();
out.newLine();
out.write("[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]");
out.newLine();
out.newLine();
String tmp = System.getProperty("user.dir");
tmp = tmp.replace("\\", "\\\\");
out.write("\"Stisys Ergebnis Checker\"=-");
out.close();
fw.close();
tmp = System.getProperty("user.dir");
tmp = tmp.replace("\\", "\\\\");
String s = "regedit /s sec.reg";
Runtime.getRuntime().exec(s);
} catch (IOException e1) {
}
}
}
}
public static JFrame getFrame() {
return frame;
}
}