diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 2170fda..69f4f77 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -67,6 +67,8 @@ public class TasksFrame extends JFrame { setupDiff(); + setupMod(); + setupArea(); setupSumFromTo(); @@ -79,6 +81,56 @@ public class TasksFrame extends JFrame { } + public void setupMod() + { + JPanel jPanel = setupPanel("Calculate modulus of two number"); + + JLabel jL1 = new JLabel(); + jL1.setText("Number a:"); + jL1.setVisible(true); + jL1.setBounds(0,20,70,30); + + JLabel jL2 = new JLabel(); + jL2.setText("Number b:"); + jL2.setVisible(true); + jL2.setBounds(0,40,70,30); + + JTextField a = new JTextField(); + a.setVisible(true); + a.setBounds(70,25,30,20); + + JTextField b = new JTextField(); + b.setVisible(true); + b.setBounds(70,45,30,20); + + JTextField result = new JTextField(); + result.setVisible(true); + result.setBounds(70,110, 30,20); + + JButton mod = new JButton("Calculate Mod"); + mod.setVisible(true); + mod.setBounds(0, 80, 180,30); + + mod.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 = calcMod(val_a, val_b); + result.setText(String.valueOf(res)); + } + }); + + jPanel.add(jL1); + jPanel.add(jL2); + jPanel.add(a); + jPanel.add(b); + jPanel.add(mod); + jPanel.add(result); + } + public int calcMod(int n, int x) { int rest = n % x;