JAVA-24699 | removing useless classes
This commit is contained in:
parent
02a680c9d6
commit
7d712320ed
|
@ -1,15 +0,0 @@
|
|||
package reminderapplication;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
public class ConstraintsBuilder {
|
||||
|
||||
static GridBagConstraints constraint(int x, int y) {
|
||||
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
gridBagConstraints.gridx = x;
|
||||
gridBagConstraints.gridy = y;
|
||||
gridBagConstraints.insets = new Insets(5, 5, 5, 5);
|
||||
return gridBagConstraints;
|
||||
}
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
package reminderapplication;
|
||||
|
||||
import static reminderapplication.ConstraintsBuilder.*;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class EditReminderFrame extends JFrame {
|
||||
|
||||
private static Timer TIMER = new Timer();
|
||||
|
||||
private final TimeReminderApplication reminderApplication;
|
||||
private final JLabel reminderTextLabel;
|
||||
private final JLabel repeatPeriodLabel;
|
||||
private final JLabel setDelayLabel;
|
||||
private final JComboBox<Integer> delay;
|
||||
private final JComboBox<Integer> period;
|
||||
private final JButton cancelButton;
|
||||
private final JButton okButton;
|
||||
private final JTextField textField;
|
||||
private final JLabel delaysLabel;
|
||||
private final JLabel periodLabel;
|
||||
|
||||
private final int reminderIndex;
|
||||
|
||||
public EditReminderFrame(TimeReminderApplication reminderApp, String reminderText, int delayInSeconds, int periodInSeconds, int index) throws HeadlessException {
|
||||
this.reminderApplication = reminderApp;
|
||||
reminderIndex = index;
|
||||
textField = createTextField(reminderText);
|
||||
delay = createDelayComboBox(delayInSeconds);
|
||||
period = createPeriodComboBox(periodInSeconds);
|
||||
cancelButton = createCancelButton();
|
||||
okButton = createOkButton();
|
||||
reminderTextLabel = createReminderTextLabel();
|
||||
repeatPeriodLabel = createRepeatPeriodLabel();
|
||||
setDelayLabel = createSetDelayLabel();
|
||||
delaysLabel = createDelaysLabel();
|
||||
periodLabel = createPeriodLabel();
|
||||
configureVisualRepresentation();
|
||||
configureActions();
|
||||
}
|
||||
|
||||
private void configureActions() {
|
||||
updateReminder();
|
||||
}
|
||||
|
||||
private void configureVisualRepresentation() {
|
||||
configureFrame();
|
||||
setLocationRelativeTo(null);
|
||||
setLayout(new GridBagLayout());
|
||||
add(reminderTextLabel, constraint(0,0));
|
||||
add(repeatPeriodLabel, constraint(1,0));
|
||||
add(setDelayLabel, constraint(2,0));
|
||||
add(textField, constraint(0, 1));
|
||||
add(delay, constraint(1, 1));
|
||||
add(period, constraint(2, 1));
|
||||
add(delaysLabel, constraint(1,3));
|
||||
add(periodLabel, constraint(2,3));
|
||||
add(okButton, constraint(1, 4));
|
||||
add(cancelButton, constraint(2, 4));
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void configureFrame() {
|
||||
setTitle("Set Reminder");
|
||||
setName("Set Reminder");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
private static JLabel createSetDelayLabel() {
|
||||
return createLabel("Set Delay", "Set Delay Label");
|
||||
}
|
||||
|
||||
private static JLabel createRepeatPeriodLabel() {
|
||||
return createLabel("Set Period", "Set Repeat Period Label");
|
||||
}
|
||||
|
||||
private static JLabel createReminderTextLabel() {
|
||||
return createLabel("Reminder Text", "Reminder Text Label");
|
||||
}
|
||||
|
||||
private JLabel createPeriodLabel() {
|
||||
return createLabel("0", "Period label");
|
||||
}
|
||||
|
||||
private JLabel createDelaysLabel() {
|
||||
return createLabel("30", "Delays Label");
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createPeriodComboBox(final int periodInSeconds) {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{0, 5, 10, 20}));
|
||||
comboBox.setSelectedItem(periodInSeconds);
|
||||
comboBox.setName("set Period");
|
||||
comboBox.addActionListener(e -> periodLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createDelayComboBox(final int delayInSeconds) {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{30, 25, 15, 5}));
|
||||
comboBox.setSelectedItem(delayInSeconds);
|
||||
comboBox.setName("set Delay");
|
||||
comboBox.addActionListener(e -> delaysLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JTextField createTextField(final String reminderText) {
|
||||
final JTextField textField = new JTextField(20);
|
||||
textField.setName("Field");
|
||||
textField.setText(reminderText);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private JButton createOkButton() {
|
||||
final JButton button = new JButton("ok");
|
||||
button.setName("OK");
|
||||
return button;
|
||||
}
|
||||
|
||||
private void updateReminder() {
|
||||
okButton.addActionListener(e -> this.dispose());
|
||||
okButton.addActionListener(e -> {
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
final int delayInSeconds = getTimeInSeconds(delay);
|
||||
final Reminder reminder = new Reminder(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
((DefaultListModel<Reminder>) reminderApplication.getReminders()).set(reminderIndex, reminder);
|
||||
});
|
||||
okButton.addActionListener(e -> scheduleReminder(textField, delay, period));
|
||||
}
|
||||
|
||||
private void scheduleReminder(final JTextField textField, final JComboBox<Integer> delay, final JComboBox<Integer> period) {
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
if (periodInSeconds == 0)
|
||||
scheduleNonRepeatedReminder(textField, delay);
|
||||
else
|
||||
scheduleRepeatedReminder(textField, delay, period);
|
||||
}
|
||||
|
||||
private void scheduleRepeatedReminder(final JTextField textField, final JComboBox<Integer> delay, final JComboBox<Integer> period) {
|
||||
final int delayInSeconds = getTimeInSeconds(delay);
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
final TimerTask timerTask = getTimerTask(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
TIMER.schedule(timerTask, TimeUnit.SECONDS.toMillis(delayInSeconds), TimeUnit.SECONDS.toMillis(periodInSeconds));
|
||||
}
|
||||
|
||||
private void scheduleNonRepeatedReminder(final JTextField textField, final JComboBox<Integer> delay) {
|
||||
final int delayInSeconds = getTimeInSeconds(delay);
|
||||
final int periodInSeconds = 0;
|
||||
final TimerTask timerTask = getTimerTask(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
TIMER.schedule(timerTask, TimeUnit.SECONDS.toMillis(delayInSeconds));
|
||||
|
||||
}
|
||||
|
||||
private int getTimeInSeconds(final JComboBox<Integer> comboBox) {
|
||||
if (comboBox != null && comboBox.getSelectedItem() != null)
|
||||
return ((Integer) comboBox.getSelectedItem());
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private TimerTask getTimerTask(final String reminderText, final Integer delayInSeconds, final Integer periodInSeconds) {
|
||||
return new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
new ReminderPopupFrame(reminderApplication, reminderText, delayInSeconds, periodInSeconds);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private JButton createCancelButton() {
|
||||
final JButton button = new JButton("cancel");
|
||||
button.setName("Cancel");
|
||||
button.addActionListener(e -> this.dispose());
|
||||
return button;
|
||||
}
|
||||
|
||||
private static JLabel createLabel(final String text, final String name) {
|
||||
JLabel label = new JLabel(text);
|
||||
label.setName(name);
|
||||
return label;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package reminderapplication;
|
||||
|
||||
public class Reminder {
|
||||
|
||||
private static String REMINDER_FORMAT = "Reminder Text: %s; Delay: %d; Period: %d;";
|
||||
|
||||
private final String name;
|
||||
private final int delay;
|
||||
private final int period;
|
||||
|
||||
public Reminder(final String name, final int delay, final int period) {
|
||||
this.name = name;
|
||||
this.delay = delay;
|
||||
this.period = period;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public int getPeriod() {
|
||||
return period;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return REMINDER_FORMAT.formatted(name, delay, period);
|
||||
}
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
package reminderapplication;
|
||||
|
||||
import static reminderapplication.ConstraintsBuilder.*;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class ReminderFrame extends JFrame {
|
||||
|
||||
private static Timer TIMER = new Timer();
|
||||
private final TimeReminderApplication reminderApplication;
|
||||
private final JLabel reminderTextLabel;
|
||||
private final JLabel repeatPeriodLabel;
|
||||
private final JLabel setDelayLabel;
|
||||
private final JComboBox<Integer> delay;
|
||||
private final JComboBox<Integer> period;
|
||||
private final JButton cancelButton;
|
||||
private final JButton okButton;
|
||||
private final JTextField textField;
|
||||
private final JLabel delaysLabel;
|
||||
private final JLabel periodLabel;
|
||||
|
||||
public ReminderFrame(TimeReminderApplication reminderApp) throws HeadlessException {
|
||||
this.reminderApplication = reminderApp;
|
||||
textField = createTextField();
|
||||
delay = createDelayComboBox();
|
||||
period = createPeriodComboBox();
|
||||
cancelButton = createCancelButton();
|
||||
okButton = createOkButton();
|
||||
reminderTextLabel = createReminderTextLabel();
|
||||
repeatPeriodLabel = createRepeatPeriodLabel();
|
||||
setDelayLabel = createSetDelayLabel();
|
||||
delaysLabel = createDelaysLabel();
|
||||
periodLabel = createPeriodLabel();
|
||||
configureVisualRepresentation();
|
||||
configureActions();
|
||||
}
|
||||
|
||||
private void configureActions() {
|
||||
createNewReminder();
|
||||
}
|
||||
|
||||
private void configureVisualRepresentation() {
|
||||
configureFrame();
|
||||
setLocationRelativeTo(null);
|
||||
setLayout(new GridBagLayout());
|
||||
add(reminderTextLabel, constraint(0,0));
|
||||
add(repeatPeriodLabel, constraint(1,0));
|
||||
add(setDelayLabel, constraint(2,0));
|
||||
add(textField, constraint(0, 1));
|
||||
add(delay, constraint(1, 1));
|
||||
add(period, constraint(2, 1));
|
||||
add(delaysLabel, constraint(1,3));
|
||||
add(periodLabel, constraint(2,3));
|
||||
add(okButton, constraint(1, 4));
|
||||
add(cancelButton, constraint(2, 4));
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void configureFrame() {
|
||||
setTitle("Set Reminder");
|
||||
setName("Set Reminder");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
private static JLabel createSetDelayLabel() {
|
||||
return createLabel("Set Delay", "Set Delay Label");
|
||||
}
|
||||
|
||||
private static JLabel createRepeatPeriodLabel() {
|
||||
return createLabel("Set Period", "Set Repeat Period Label");
|
||||
}
|
||||
|
||||
private static JLabel createReminderTextLabel() {
|
||||
return createLabel("Reminder Text", "Reminder Text Label");
|
||||
}
|
||||
|
||||
private JLabel createPeriodLabel() {
|
||||
return createLabel("0", "Period label");
|
||||
}
|
||||
|
||||
private JLabel createDelaysLabel() {
|
||||
return createLabel("30", "Delays Label");
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createPeriodComboBox() {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{0, 5, 10, 20}));
|
||||
comboBox.setName("set Period");
|
||||
comboBox.addActionListener(e -> periodLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createDelayComboBox() {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{30, 25, 15, 5}));
|
||||
comboBox.setName("set Delay");
|
||||
comboBox.addActionListener(e -> delaysLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JTextField createTextField() {
|
||||
final JTextField textField = new JTextField(20);
|
||||
textField.setName("Field");
|
||||
return textField;
|
||||
}
|
||||
|
||||
private JButton createOkButton() {
|
||||
final JButton button = new JButton("ok");
|
||||
button.setName("OK");
|
||||
return button;
|
||||
}
|
||||
|
||||
private void createNewReminder() {
|
||||
|
||||
okButton.addActionListener(e -> this.dispose());
|
||||
okButton.addActionListener(e -> {
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
final int delayInSeconds = getTimeInSeconds(delay);
|
||||
final Reminder reminder = new Reminder(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
((DefaultListModel<Reminder>) reminderApplication.getReminders()).addElement(reminder);
|
||||
});
|
||||
okButton.addActionListener(e -> scheduleReminder(textField, delay, period));
|
||||
}
|
||||
|
||||
private void scheduleReminder(final JTextField textField, final JComboBox<Integer> delay, final JComboBox<Integer> period) {
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
if (periodInSeconds == 0)
|
||||
scheduleNonRepeatedReminder(textField, delay);
|
||||
else
|
||||
scheduleRepeatedReminder(textField, delay, period);
|
||||
}
|
||||
|
||||
private void scheduleRepeatedReminder(final JTextField textField, final JComboBox<Integer> delay, final JComboBox<Integer> period) {
|
||||
final int delayInSeconds = getTimeInSeconds(delay) + 200;
|
||||
final int periodInSeconds = getTimeInSeconds(period);
|
||||
final TimerTask timerTask = getTimerTask(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
TIMER.schedule(timerTask, TimeUnit.SECONDS.toMillis(delayInSeconds), TimeUnit.SECONDS.toMillis(periodInSeconds));
|
||||
}
|
||||
|
||||
private void scheduleNonRepeatedReminder(final JTextField textField, final JComboBox<Integer> delay) {
|
||||
final int delayInSeconds = getTimeInSeconds(delay);
|
||||
final int periodInSeconds = 0;
|
||||
final TimerTask timerTask = getTimerTask(textField.getText(), delayInSeconds, periodInSeconds);
|
||||
TIMER.schedule(timerTask, TimeUnit.SECONDS.toMillis(delayInSeconds));
|
||||
|
||||
}
|
||||
|
||||
private int getTimeInSeconds(final JComboBox<Integer> comboBox) {
|
||||
if (comboBox != null && comboBox.getSelectedItem() != null)
|
||||
return ((Integer) comboBox.getSelectedItem());
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private TimerTask getTimerTask(final String reminderText, final Integer delayInSeconds, final Integer periodInSeconds) {
|
||||
return new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
new ReminderPopupFrame(reminderApplication, reminderText, delayInSeconds, periodInSeconds);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private JButton createCancelButton() {
|
||||
final JButton button = new JButton("cancel");
|
||||
button.setName("Cancel");
|
||||
button.addActionListener(e -> this.dispose());
|
||||
return button;
|
||||
}
|
||||
|
||||
private static JLabel createLabel(final String text, final String name) {
|
||||
JLabel label = new JLabel(text);
|
||||
label.setName(name);
|
||||
return label;
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
package reminderapplication;
|
||||
|
||||
import static reminderapplication.ConstraintsBuilder.*;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class ReminderPopupFrame extends JFrame {
|
||||
|
||||
private static final Timer TIMER = new Timer();
|
||||
private final int AUTOMATIC_CLOSE_TIME_IN_SECONDS = 10;
|
||||
private final TimeReminderApplication reminderApplication;
|
||||
private final JLabel reminderTextLabel;
|
||||
private final JLabel repeatPeriodLabel;
|
||||
private final JLabel setDelayLabel;
|
||||
private final JComboBox<Integer> delay;
|
||||
private final JComboBox<Integer> period;
|
||||
private final JButton cancelButton;
|
||||
private final JButton okButton;
|
||||
private final JTextField textField;
|
||||
private final JLabel delaysLabel;
|
||||
private final JLabel periodLabel;
|
||||
|
||||
public ReminderPopupFrame(TimeReminderApplication reminderApp, final String text, final Integer delayInSeconds, final Integer periodInSeconds) throws HeadlessException {
|
||||
this.reminderApplication = reminderApp;
|
||||
textField = createTextField(text);
|
||||
delay = createDelayComboBox(delayInSeconds);
|
||||
period = createPeriodComboBox(periodInSeconds);
|
||||
cancelButton = createCancelButton();
|
||||
okButton = createDisabledOkButton();
|
||||
reminderTextLabel = createReminderTextLabel();
|
||||
repeatPeriodLabel = createRepeatPeriodLabel();
|
||||
setDelayLabel = createSetDelayLabel();
|
||||
delaysLabel = createDelaysLabel();
|
||||
periodLabel = createPeriodLabel();
|
||||
configureVisualRepresentation();
|
||||
configureActions();
|
||||
}
|
||||
|
||||
private void configureActions() {
|
||||
scheduleClosing();
|
||||
}
|
||||
|
||||
private void scheduleClosing() {
|
||||
final TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReminderPopupFrame.this.dispose();
|
||||
}
|
||||
};
|
||||
TIMER.schedule(timerTask, TimeUnit.SECONDS.toMillis(AUTOMATIC_CLOSE_TIME_IN_SECONDS));
|
||||
}
|
||||
|
||||
private void configureVisualRepresentation() {
|
||||
configureFrame();
|
||||
setLocationRelativeTo(null);
|
||||
setLayout(new GridBagLayout());
|
||||
add(reminderTextLabel, constraint(0,0));
|
||||
add(repeatPeriodLabel, constraint(1,0));
|
||||
add(setDelayLabel, constraint(2,0));
|
||||
add(textField, constraint(0, 1));
|
||||
add(delay, constraint(1, 1));
|
||||
add(period, constraint(2, 1));
|
||||
add(delaysLabel, constraint(1,3));
|
||||
add(periodLabel, constraint(2,3));
|
||||
add(okButton, constraint(1, 4));
|
||||
add(cancelButton, constraint(2, 4));
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void configureFrame() {
|
||||
setTitle("Set Reminder");
|
||||
setName("Set Reminder");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
}
|
||||
|
||||
private static JLabel createSetDelayLabel() {
|
||||
return createLabel("Set Delay", "Set Delay Label");
|
||||
}
|
||||
|
||||
private static JLabel createRepeatPeriodLabel() {
|
||||
return createLabel("Set Period", "Set Repeat Period Label");
|
||||
}
|
||||
|
||||
private static JLabel createReminderTextLabel() {
|
||||
return createLabel("Reminder Text", "Reminder Text Label");
|
||||
}
|
||||
|
||||
private JLabel createPeriodLabel() {
|
||||
return createLabel("0", "Period label");
|
||||
}
|
||||
|
||||
private JLabel createDelaysLabel() {
|
||||
return createLabel("30", "Delays Label");
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createPeriodComboBox(final Integer periodInSeconds) {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{0, 5, 10, 20}));
|
||||
comboBox.setName("set Period");
|
||||
comboBox.setSelectedItem(periodInSeconds);
|
||||
comboBox.addActionListener(e -> periodLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JComboBox<Integer> createDelayComboBox(Integer delay) {
|
||||
final JComboBox<Integer> comboBox = new JComboBox<>(new DefaultComboBoxModel<>(new Integer[]{30, 25, 15, 5}));
|
||||
comboBox.setSelectedItem(delay);
|
||||
comboBox.setName("set Delay");
|
||||
comboBox.addActionListener(e -> delaysLabel.setText(comboBox.getSelectedItem().toString()));
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private JTextField createTextField(final String text) {
|
||||
final JTextField textField = new JTextField(20);
|
||||
textField.setName("Field");
|
||||
textField.setText(text);
|
||||
return textField;
|
||||
}
|
||||
|
||||
private JButton createDisabledOkButton() {
|
||||
final JButton button = new JButton("ok");
|
||||
button.setName("OK");
|
||||
button.setEnabled(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
private JButton createCancelButton() {
|
||||
final JButton button = new JButton("cancel");
|
||||
button.setName("Cancel");
|
||||
button.addActionListener(e -> this.dispose());
|
||||
return button;
|
||||
}
|
||||
|
||||
private static JLabel createLabel(final String text, final String name) {
|
||||
JLabel label = new JLabel(text);
|
||||
label.setName(name);
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
## Relevant articles:
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>memory-leaks</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>memory-leaks</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources/</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/test/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
|
@ -1,11 +0,0 @@
|
|||
package com.baeldung;
|
||||
|
||||
public class Key {
|
||||
|
||||
public static String key;
|
||||
|
||||
public Key(String key) {
|
||||
Key.key = key;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
//package com.baeldung;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.InputStreamReader;
|
||||
//import java.net.URISyntaxException;
|
||||
//import java.net.URL;
|
||||
//import java.net.URLConnection;
|
||||
//import java.nio.charset.StandardCharsets;
|
||||
//import java.nio.file.Files;
|
||||
//import java.nio.file.Paths;
|
||||
//import java.nio.file.StandardOpenOption;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Map;
|
||||
//import java.util.Random;
|
||||
//import java.util.Scanner;
|
||||
//
|
||||
//import org.junit.FixMethodOrder;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.junit.runners.JUnit4;
|
||||
//import org.junit.runners.MethodSorters;
|
||||
//
|
||||
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
//@RunWith(JUnit4.class)
|
||||
//public class MemoryLeaksTest {
|
||||
// private Random random = new Random();
|
||||
// public static final ArrayList<Double> list = new ArrayList<Double>(1000000);
|
||||
//
|
||||
// @Test
|
||||
// public void givenStaticField_whenLotsOfOperations_thenMemoryLeak() throws InterruptedException {
|
||||
// for (int i = 0; i < 1000000; i++) {
|
||||
// list.add(random.nextDouble());
|
||||
// }
|
||||
// System.gc();
|
||||
// Thread.sleep(10000); //to allow GC do its job
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void givenNormalField_whenLotsOfOperations_thenGCWorksFine() throws InterruptedException {
|
||||
// addElementsToTheList();
|
||||
// System.gc();
|
||||
// Thread.sleep(10000); //to allow GC do its job
|
||||
// }
|
||||
//
|
||||
// private void addElementsToTheList(){
|
||||
// ArrayList<Double> list = new ArrayList<Double>(1000000);
|
||||
// for (int i = 0; i < 1000000; i++) {
|
||||
// list.add(random.nextDouble());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "resource" })
|
||||
// @Test(expected = OutOfMemoryError.class)
|
||||
// public void givenLengthString_whenIntern_thenOutOfMemory() throws IOException, InterruptedException {
|
||||
// Thread.sleep(15000);
|
||||
// String str = new Scanner(new File("src/test/resources/large.txt"), "UTF-8").useDelimiter("\\A")
|
||||
// .next();
|
||||
// System.gc();
|
||||
// str.intern();
|
||||
// Thread.sleep(10000);
|
||||
// }
|
||||
//
|
||||
// @Test(expected = OutOfMemoryError.class)
|
||||
// public void givenURL_whenUnclosedStream_thenOutOfMemory() throws IOException, URISyntaxException {
|
||||
// String str = "";
|
||||
// URLConnection conn = new URL("http:norvig.com/big.txt").openConnection();
|
||||
// BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
// while (br.readLine() != null) {
|
||||
// str += br.readLine();
|
||||
// }
|
||||
// Files.write(Paths.get("src/main/resources/"), str.getBytes(), StandardOpenOption.CREATE);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unused")
|
||||
// @Test(expected = OutOfMemoryError.class)
|
||||
// public void givenConnection_whenUnclosed_thenOutOfMemory() throws IOException, URISyntaxException {
|
||||
// URL url = new URL("ftp:speedtest.tele2.net");
|
||||
// URLConnection urlc = url.openConnection();
|
||||
// InputStream is = urlc.getInputStream();
|
||||
// String str = "";
|
||||
// while (true) {
|
||||
// str += is.toString()
|
||||
// .intern();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test(expected = OutOfMemoryError.class)
|
||||
// public void givenMap_whenNoEqualsNoHashCodeMethods_thenOutOfMemory() throws IOException, URISyntaxException {
|
||||
// Map<Object, Object> map = System.getProperties();
|
||||
// while (true) {
|
||||
// map.put(new Key("key"), "value");
|
||||
// }
|
||||
// }
|
||||
//}
|
Loading…
Reference in New Issue