Browse Source

Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	src/main/java/src/TasksFrame.java
remotes/origin/develop
fdai6040 2 years ago
parent
commit
80808b4b8d
  1. 107
      src/main/java/src/TasksFrame.java
  2. 34
      src/test/java/src/TasksFrameTest.java

107
src/main/java/src/TasksFrame.java

@ -18,13 +18,13 @@ public class TasksFrame extends JFrame {
super("Unsere kleinen Tasks");
setVisible(true);
setBounds(810,200, 300, 600);
setPreferredSize(new Dimension(300, 600));
setBounds(810,200, 400, 600);
setPreferredSize(new Dimension(400, 600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
JPanel root = new JPanel();
root.setBounds(0, 0, 300, 600);
root.setBounds(0, 0, 400, 600);
root.setVisible(true);
setContentPane(root);
@ -35,7 +35,7 @@ public class TasksFrame extends JFrame {
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));
jScrollPane.setPreferredSize(new Dimension(400, 600));
root.add(jScrollPane);
}
@ -52,7 +52,7 @@ public class TasksFrame extends JFrame {
JLabel jLabel = new JLabel(header);
jLabel.setVisible(true);
jLabel.setBounds(3, 3, 160, 20);
jLabel.setBounds(3, 3, 300, 20);
panel.add(jLabel);
@ -67,6 +67,8 @@ public class TasksFrame extends JFrame {
setupDiff();
setupArea();
setupSumFromTo();
setup5ModList(1, 20);
@ -118,6 +120,12 @@ public class TasksFrame extends JFrame {
}
public int calcMod(int n, int x)
{
int rest = n % x;
return rest;
}
private void setupEulerschePhiFunk() {
JPanel jPanel = setupPanel("Eulersche Phi Funktion");
@ -311,6 +319,92 @@ public class TasksFrame extends JFrame {
return a-b;
}
public void setupArea()
{
JPanel jPanel = setupPanel("Area and perimeter of a Rectangle:");
JLabel jL1 = new JLabel();
jL1.setText("Side a:");
jL1.setVisible(true);
jL1.setBounds(0,20,50,30);
JLabel jL2 = new JLabel();
jL2.setText("Side b:");
jL2.setVisible(true);
jL2.setBounds(0,40,50,30);
JTextField a = new JTextField();
a.setVisible(true);
a.setBounds(50,25,30,20);
JTextField b = new JTextField();
b.setVisible(true);
b.setBounds(50,45,30,20);
JButton area = new JButton("Calculate area");
area.setVisible(true);
area.setBounds(0, 80, 180,30);
JTextField areaRes = new JTextField();
areaRes.setBounds(200,80,30,20 );
areaRes.setVisible(true);
area.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);
Integer res = calcArea(val_a, val_b);
areaRes.setText(String.valueOf(res));
}
});
jPanel.add(jL1);
jPanel.add(jL2);
jPanel.add(a);
jPanel.add(b);
jPanel.add(area);
jPanel.add(areaRes);
JButton perimeter = new JButton("Calculate perimeter");
perimeter.setVisible(true);
perimeter.setBounds(0, 110, 180,30);
JTextField perimeterRes = new JTextField();
perimeterRes.setBounds(200,110,30,20 );
perimeterRes.setVisible(true);
perimeter.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);
Integer res = calcPerimeter(val_a, val_b);
perimeterRes.setText(String.valueOf(res));
}
});
jPanel.add(perimeterRes);
jPanel.add(perimeter);
}
public int calcArea(int a, int b)
{
int area = a * b;
return area;
}
public int calcPerimeter(int a, int b)
{
int perimeter = 2 * (a+b);
return perimeter;
}
public void setupSumFromTo(){
@ -347,6 +441,7 @@ public class TasksFrame extends JFrame {
jPanel.add(b);
jPanel.add(result);
jPanel.add(sumFromTo);
}
public int sumCalc(int from, int to) {
@ -398,4 +493,6 @@ public class TasksFrame extends JFrame {
return sum;
}
}

34
src/test/java/src/TasksFrameTest.java

@ -69,6 +69,40 @@ class TasksFrameTest {
int ggt3 = tasksFrame.ggt(262, 599);
assertEquals(1, ggt3);
}
@Test
void setupArea()
{
TasksFrame tasksFrame = new TasksFrame();
int p1 = tasksFrame.calcArea(3,5);
assertEquals(15, p1);
int p2= tasksFrame.calcArea(0,7);
assertEquals(0,p2);
}
@Test
void setupPerimeter()
{
TasksFrame tasksFrame = new TasksFrame();
int p1 = tasksFrame.calcPerimeter(3,5);
assertEquals(16, p1);
int p2= tasksFrame.calcArea(0,7);
assertEquals(0,p2);
}
@Test
void setupMod()
{
TasksFrame tasksFrame = new TasksFrame();
int p1= tasksFrame.calcMod(5,3);
assertEquals(2,p1);
int p2 = tasksFrame.calcMod(4,2);
assertEquals(0,p2);
int p3= tasksFrame.calcMod(10,3);
assertEquals(1,p3);
}
}

Loading…
Cancel
Save