-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create getActiveEvents method in Event service and its tests
Created the getActiveEvents to fetch present events
- Loading branch information
1 parent
346a959
commit 0f66dc6
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
import java.awt.event.*; | ||
import java.awt.FlowLayout; | ||
import javax.swing.event.*; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class NumbersApp extends JFrame { | ||
private JTextField factorField; | ||
private JList<Integer> list; | ||
private JButton addButton; | ||
private Integer[] numbers = new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4)}; | ||
public NumbersApp() { | ||
factorField = new JTextField("3", 10); | ||
list = new JList<Integer>(numbers); | ||
addButton = new JButton("Add"); | ||
JPanel commandpanel = new JPanel(); | ||
commandpanel.add(list); | ||
commandpanel.add(factorField); | ||
commandpanel.add(addButton); | ||
getContentPane().add(commandpanel, BorderLayout.NORTH); | ||
addButton.addActionListener( new AddFactorListener() ); | ||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
setSize(600, 200); | ||
setVisible(true); | ||
} | ||
//complete this | ||
// We create a AddFactorListener class that implements ActionListener | ||
class AddFactorListener implements ActionListener { | ||
// This actionPerformed method runs when the button clicks | ||
public void actionPerformed(ActionEvent e) { | ||
// jijiku use try n catch because if not an integer, we dont do anything | ||
try { | ||
// parse the text field as an integer | ||
int factor = Integer.parseInt(factorField.getText()); | ||
// loop all numbers n try to add the factor | ||
for(int i = 0; i < numbers.length; i++){ | ||
numbers[i] += factor; | ||
} | ||
// update the java thingy | ||
list.updateUI(); | ||
} catch (NumberFormatException ex) { | ||
// if not an integer, we set the text field to 3 | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
javax.swing.SwingUtilities.invokeLater(new Runnable() { | ||
public void run() {new NumbersApp();} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters