fdai6499
2 years ago
2 changed files with 175 additions and 0 deletions
@ -0,0 +1,172 @@ |
|||||
|
package src; |
||||
|
|
||||
|
import javax.swing.*; |
||||
|
import javax.swing.border.EmptyBorder; |
||||
|
import java.awt.*; |
||||
|
import java.awt.event.ActionEvent; |
||||
|
import java.awt.event.ActionListener; |
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
public class TasksFrame extends JFrame { |
||||
|
|
||||
|
private final JScrollPane jScrollPane; |
||||
|
private JPanel container; |
||||
|
|
||||
|
public TasksFrame() throws HeadlessException { |
||||
|
|
||||
|
super("Unsere kleinen Tasks"); |
||||
|
|
||||
|
setVisible(true); |
||||
|
setBounds(810,200, 300, 600); |
||||
|
setPreferredSize(new Dimension(300, 600)); |
||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
|
setResizable(false); |
||||
|
|
||||
|
JPanel root = new JPanel(); |
||||
|
root.setBounds(0, 0, 300, 600); |
||||
|
root.setVisible(true); |
||||
|
|
||||
|
setContentPane(root); |
||||
|
|
||||
|
container = new JPanel(); |
||||
|
container.setBorder(new EmptyBorder(new Insets(3, 3, 3, 3))); |
||||
|
container.setBackground(new Color(0x839683)); |
||||
|
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); |
||||
|
|
||||
|
jScrollPane = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
||||
|
jScrollPane.setPreferredSize(new Dimension(300, 600)); |
||||
|
root.add(jScrollPane); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private JPanel setupPanel(String header) { |
||||
|
|
||||
|
JPanel panel = new JPanel(); |
||||
|
panel.setPreferredSize(new Dimension(270, 150)); |
||||
|
panel.setVisible(true); |
||||
|
panel.setLayout(null); |
||||
|
|
||||
|
container.add(panel); |
||||
|
container.add(Box.createVerticalStrut(5)); |
||||
|
|
||||
|
JLabel jLabel = new JLabel(header); |
||||
|
jLabel.setVisible(true); |
||||
|
jLabel.setBounds(3, 3, 160, 20); |
||||
|
|
||||
|
panel.add(jLabel); |
||||
|
|
||||
|
return panel; |
||||
|
} |
||||
|
|
||||
|
public void run() { |
||||
|
|
||||
|
setupHelloWorld(); |
||||
|
|
||||
|
setupSum(); |
||||
|
|
||||
|
setupSumCalc(0, 10); |
||||
|
|
||||
|
setup5ModList(1, 20); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private ArrayList<Integer> setup5ModList(int from, int to) { |
||||
|
|
||||
|
ArrayList<Integer> mods = new ArrayList<>(); |
||||
|
|
||||
|
JTextField jTextField = new JTextField(); |
||||
|
jTextField.setVisible(true); |
||||
|
jTextField.setBounds(3, 40, 250, 30); |
||||
|
|
||||
|
for (int i = from; i < to; i++) { |
||||
|
int e = i % 5; |
||||
|
mods.add(e); |
||||
|
jTextField.setText(jTextField.getText() + String.valueOf(e) + " "); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
JPanel jPanel = setupPanel("mods 2"); |
||||
|
jPanel.add(jTextField); |
||||
|
|
||||
|
return mods; |
||||
|
} |
||||
|
|
||||
|
private void setupSumCalc(int from, int to) { |
||||
|
|
||||
|
JPanel jPanel = setupPanel("Sum from to"); |
||||
|
|
||||
|
JLabel jLabel = new JLabel(); |
||||
|
jLabel.setVisible(true); |
||||
|
jLabel.setBounds(30, 30, 50, 20); |
||||
|
|
||||
|
int sum = 0; |
||||
|
for (int i = from; i < to; i++) { |
||||
|
sum += i; |
||||
|
} |
||||
|
|
||||
|
jLabel.setText(String.valueOf(sum)); |
||||
|
|
||||
|
jPanel.add(jLabel); |
||||
|
} |
||||
|
|
||||
|
private void setupSum() { |
||||
|
JPanel jPanel = setupPanel("Summe"); |
||||
|
|
||||
|
JTextField a = new JTextField(); |
||||
|
a.setBounds(10, 50, 30, 20); |
||||
|
a.setVisible(true); |
||||
|
|
||||
|
JTextField b = new JTextField(); |
||||
|
b.setBounds(50, 50, 30, 20); |
||||
|
b.setVisible(true); |
||||
|
|
||||
|
JTextField result = new JTextField(); |
||||
|
result.setBounds(100, 50, 30, 20); |
||||
|
result.setVisible(true); |
||||
|
|
||||
|
JButton add = new JButton("add"); |
||||
|
add.setBounds(10, 90, 100, 30); |
||||
|
add.setVisible(true); |
||||
|
add.addActionListener(new ActionListener() { |
||||
|
@Override |
||||
|
public void actionPerformed(ActionEvent e) { |
||||
|
String texta = a.getText(); |
||||
|
String textb = b.getText(); |
||||
|
Integer val_a = Integer.valueOf(texta); |
||||
|
Integer val_b = Integer.valueOf(textb); |
||||
|
result.setText(String.valueOf(val_a+val_b)); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
jPanel.add(a); |
||||
|
jPanel.add(b); |
||||
|
jPanel.add(result); |
||||
|
jPanel.add(add); |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
private void setupHelloWorld() { |
||||
|
|
||||
|
JPanel jPanel = setupPanel("Hello World"); |
||||
|
|
||||
|
JLabel jLabel = new JLabel(); |
||||
|
jLabel.setBounds(20, 80, 150, 30); |
||||
|
jLabel.setVisible(true); |
||||
|
|
||||
|
Button button = new Button("Say Hello World"); |
||||
|
button.setBounds(10, 50, 150, 30); |
||||
|
button.setVisible(true); |
||||
|
button.addActionListener(new ActionListener() { |
||||
|
@Override |
||||
|
public void actionPerformed(ActionEvent e) { |
||||
|
jLabel.setText("Hello World"); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
jPanel.add(jLabel); |
||||
|
jPanel.add(button); |
||||
|
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue