|
@ -66,7 +66,7 @@ public class TasksFrame extends JFrame { |
|
|
|
|
|
|
|
|
setupDiff(); |
|
|
setupDiff(); |
|
|
|
|
|
|
|
|
setupSumCalc(0, 10); |
|
|
|
|
|
|
|
|
setupSumFromTo(); |
|
|
|
|
|
|
|
|
setup5ModList(1, 20); |
|
|
setup5ModList(1, 20); |
|
|
|
|
|
|
|
@ -207,22 +207,51 @@ public class TasksFrame extends JFrame { |
|
|
return a-b; |
|
|
return a-b; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void setupSumCalc(int from, int to) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setupSumFromTo(){ |
|
|
|
|
|
|
|
|
JPanel jPanel = setupPanel("Sum from to"); |
|
|
JPanel jPanel = setupPanel("Sum from to"); |
|
|
|
|
|
|
|
|
JLabel jLabel = new JLabel(); |
|
|
|
|
|
jLabel.setVisible(true); |
|
|
|
|
|
jLabel.setBounds(30, 30, 50, 20); |
|
|
|
|
|
|
|
|
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, 40, 20); |
|
|
|
|
|
result.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
JButton sumFromTo = new JButton("calculate"); |
|
|
|
|
|
sumFromTo.setBounds(10,90,100,30); |
|
|
|
|
|
sumFromTo.setVisible(true); |
|
|
|
|
|
|
|
|
|
|
|
sumFromTo.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 = sumCalc(val_a, val_b); |
|
|
|
|
|
result.setText(String.valueOf(res)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
jPanel.add(a); |
|
|
|
|
|
jPanel.add(b); |
|
|
|
|
|
jPanel.add(result); |
|
|
|
|
|
jPanel.add(sumFromTo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int sumCalc(int from, int to) { |
|
|
|
|
|
|
|
|
int sum = 0; |
|
|
int sum = 0; |
|
|
for (int i = from; i < to; i++) { |
|
|
for (int i = from; i < to; i++) { |
|
|
sum += i; |
|
|
sum += i; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
jLabel.setText(String.valueOf(sum)); |
|
|
|
|
|
|
|
|
|
|
|
jPanel.add(jLabel); |
|
|
|
|
|
|
|
|
return sum+to; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|