init commit
This commit is contained in:
94
src/com/rkcsd/apps/demo/gui/MainWindow.java
Normal file
94
src/com/rkcsd/apps/demo/gui/MainWindow.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.rkcsd.apps.demo.gui;
|
||||
|
||||
import com.rkcsd.apps.demo.main.Calculator;
|
||||
import com.rkcsd.apps.demo.main.Main;
|
||||
import com.rkcsd.apps.demo.main.StringToNumberConverter;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class MainWindow extends JFrame {
|
||||
|
||||
private JTextField input1;
|
||||
private JTextField input2;
|
||||
|
||||
private JLabel text;
|
||||
|
||||
private JButton btnPrinterList;
|
||||
private JButton btnAdminPanel;
|
||||
private JButton btnExit;
|
||||
|
||||
private JComboBox cbx;
|
||||
|
||||
public MainWindow() {
|
||||
super("Meine Anwendung");
|
||||
this.setSize(1000, 500);
|
||||
|
||||
this.setLayout(null);
|
||||
|
||||
btnPrinterList = new JButton("DL Anzeigen");
|
||||
btnPrinterList.setBounds(10, 210, 500, 20);
|
||||
btnPrinterList.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
PrinterListWindow secondWindow = new PrinterListWindow(MainWindow.this);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
this.add(btnPrinterList);
|
||||
|
||||
btnAdminPanel = new JButton("Admin Panel öffnen");
|
||||
btnAdminPanel.setBounds(10, 105, 500, 20);
|
||||
btnAdminPanel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
MainWindow second = new MainWindow();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
this.add(btnAdminPanel);
|
||||
|
||||
btnExit = new JButton("Beenden");
|
||||
btnExit.setBounds(500, 315, 500, 20);
|
||||
btnExit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
this.add(btnExit);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private void doAction() {
|
||||
StringToNumberConverter stnc1 = new StringToNumberConverter(input1.getText());
|
||||
StringToNumberConverter stnc2 = new StringToNumberConverter(input2.getText());
|
||||
|
||||
double d1 = stnc1.doConversion();
|
||||
double d2 = stnc2.doConversion();
|
||||
|
||||
if (stnc1.hasError() || stnc2.hasError()) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Da ging wohl was schief");
|
||||
} else {
|
||||
Calculator calc = new Calculator(d1, d2);
|
||||
if (cbx.getSelectedItem().equals("+")) {
|
||||
calc.doAdd();
|
||||
} else if (cbx.getSelectedItem().equals("-")) {
|
||||
calc.doSubtract();
|
||||
}
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Das Ergebnis lautet: " + calc.getResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user