package gui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import static java.lang.Integer.*;
/**
*
* @author ToGo
*/
public class OptionPanel extends javax.swing.JFrame {
private Properties properties;
private void load(File file) throws IOException {
properties = new Properties();
if (file.exists()) {
properties.load(new FileInputStream(file));
}
minSpeedSlider.setValue(parseInt(properties.getProperty("minSpeed", "500")));
maxSpeedSlider.setValue(parseInt(properties.getProperty("maxSpeed", "800")));
minRadiusSlider.setValue(parseInt(properties.getProperty("minRadius", "60")));
maxRadiusSlider.setValue(parseInt(properties.getProperty("maxRadius", "400")));
expandTimeSlider.setValue(parseInt(properties.getProperty("expandTime", "400")));
widthField.setText(properties.getProperty("frameWidth", "640"));
heightField.setText(properties.getProperty("frameHeight", "400"));
ballCountField.setText(properties.getProperty("ballCount", "50"));
explodeCountField.setText(properties.getProperty("explodeCount", "34"));
backgroundColorLabel.setBackground(Color.decode(properties.getProperty("background", "0x090507")));
}
private void save(File file) throws IOException {
properties.setProperty("minSpeed", String.valueOf(minSpeedSlider.getValue()));
properties.setProperty("maxSpeed", String.valueOf(maxSpeedSlider.getValue()));
properties.setProperty("minRadius", String.valueOf(minRadiusSlider.getValue()));
properties.setProperty("maxRadius", String.valueOf(maxRadiusSlider.getValue()));
properties.setProperty("expandTime", String.valueOf(expandTimeSlider.getValue()));
properties.setProperty("frameWidth", widthField.getText());
properties.setProperty("frameHeight", heightField.getText());
properties.setProperty("ballCount", ballCountField.getText());
properties.setProperty("explodeCount", explodeCountField.getText());
properties.setProperty("background", toHexString(backgroundColorLabel.getBackground()));
properties.store(new FileOutputStream(file), "");
}
/** Creates new form OptionPanel */
public OptionPanel() {
initComponents();
setLocationRelativeTo(null);
reset();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
maxSpeedSlider = new javax.swing.JSlider();
jLabel2 = new javax.swing.JLabel();
minSpeedSlider = new javax.swing.JSlider();
jLabel3 = new javax.swing.JLabel();
maxRadiusSlider = new javax.swing.JSlider();
jLabel4 = new javax.swing.JLabel();
minRadiusSlider = new javax.swing.JSlider();
jLabel5 = new javax.swing.JLabel();
expandTimeSlider = new javax.swing.JSlider();
jPanel2 = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
widthField = new javax.swing.JTextField();
heightField = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
jLabel8 = new javax.swing.JLabel();
ballCountField = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
explodeCountField = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
backgroundColorLabel = new javax.swing.JLabel();
startButton = new javax.swing.JButton();
loadButton = new javax.swing.JButton();
saveButton = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ChnRxn Configuration");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ball Properties"));
jLabel1.setText("Max Speed :");
maxSpeedSlider.setMaximum(1000);
maxSpeedSlider.setPaintLabels(true);
maxSpeedSlider.setPaintTicks(true);
maxSpeedSlider.setValue(800);
maxSpeedSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
maxSpeedSliderStateChanged(evt);
}
});
jLabel2.setText("Min Speed : ");
minSpeedSlider.setMaximum(1000);
minSpeedSlider.setPaintLabels(true);
minSpeedSlider.setPaintTicks(true);
minSpeedSlider.setValue(500);
minSpeedSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
minSpeedSliderStateChanged(evt);
}
});
jLabel3.setText("Max Radius : ");
maxRadiusSlider.setMaximum(1000);
maxRadiusSlider.setPaintLabels(true);
maxRadiusSlider.setPaintTicks(true);
maxRadiusSlider.setValue(400);
maxRadiusSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
maxRadiusSliderStateChanged(evt);
}
});
jLabel4.setText("Min Radius : ");
minRadiusSlider.setMaximum(1000);
minRadiusSlider.setPaintLabels(true);
minRadiusSlider.setPaintTicks(true);
minRadiusSlider.setValue(60);
minRadiusSlider.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
minRadiusSliderStateChanged(evt);
}
});
jLabel5.setText("Fade In/Out Time : ");
expandTimeSlider.setMaximum(1000);
expandTimeSlider.setPaintLabels(true);
expandTimeSlider.setPaintTicks(true);
expandTimeSlider.setValue(425);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addComponent(maxSpeedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addComponent(minSpeedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addComponent(maxRadiusSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addComponent(minRadiusSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(expandTimeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(maxSpeedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(minSpeedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(maxRadiusSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(minRadiusSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5)
.addComponent(expandTimeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Frame Properties"));
jLabel6.setText("Width : ");
jLabel7.setText("Height : ");
widthField.setText("640");
heightField.setText("400");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(heightField)
.addComponent(widthField, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel6, jLabel7});
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(widthField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(heightField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Game Properties"));
jLabel8.setText("Total Number of Balls : ");
ballCountField.setText("54");
jLabel9.setText("Number of Balls to Explode : ");
explodeCountField.setText("40");
jLabel10.setText("Background Color : ");
backgroundColorLabel.setBackground(new java.awt.Color(51, 255, 0));
backgroundColorLabel.setOpaque(true);
backgroundColorLabel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
backgroundColorLabelMouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel9)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(backgroundColorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ballCountField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
.addComponent(explodeCountField, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel8, jLabel9});
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(ballCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(explodeCountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(backgroundColorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
startButton.setText("Start!");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startButtonActionPerformed(evt);
}
});
loadButton.setText("Load");
loadButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadButtonActionPerformed(evt);
}
});
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
jButton1.setText("Reset");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(loadButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(startButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(startButton)
.addComponent(loadButton)
.addComponent(saveButton)
.addComponent(jButton1)))
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("ChnRxn");
final RxnPanel rxnPanel = new RxnPanel(frame);
rxnPanel.restartGame(
minRadiusSlider.getValue(), maxRadiusSlider.getValue(),
expandTimeSlider.getValue(),
minSpeedSlider.getValue(), maxSpeedSlider.getValue(),
Integer.parseInt(ballCountField.getText()),
Integer.parseInt(explodeCountField.getText()),
new Dimension(Integer.parseInt(widthField.getText()),
Integer.parseInt(heightField.getText())),
backgroundColorLabel.getBackground());
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
rxnPanel.getManager().stop();
OptionPanel.this.setVisible(true);
}
});
frame.add(rxnPanel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
this.setVisible(false);
}//GEN-LAST:event_startButtonActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
minRadiusSlider.setValue(60);
maxRadiusSlider.setValue(400);
expandTimeSlider.setValue(400);
minSpeedSlider.setValue(500);
maxSpeedSlider.setValue(800);
ballCountField.setText("50");
explodeCountField.setText("34");
widthField.setText("640");
heightField.setText("400");
backgroundColorLabel.setBackground(Color.decode("0x090507"));
}//GEN-LAST:event_jButton1ActionPerformed
private void maxSpeedSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxSpeedSliderStateChanged
if (maxSpeedSlider.getValue() < minSpeedSlider.getValue()) {
maxSpeedSlider.setValue(minSpeedSlider.getValue());
maxSpeedSlider.updateUI();
}
}//GEN-LAST:event_maxSpeedSliderStateChanged
private void minSpeedSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minSpeedSliderStateChanged
if (minSpeedSlider.getValue() > maxSpeedSlider.getValue()) {
minSpeedSlider.setValue(maxSpeedSlider.getValue());
minSpeedSlider.updateUI();
}
}//GEN-LAST:event_minSpeedSliderStateChanged
private void maxRadiusSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxRadiusSliderStateChanged
if (maxRadiusSlider.getValue() < minRadiusSlider.getValue()) {
maxRadiusSlider.setValue(minRadiusSlider.getValue());
maxRadiusSlider.updateUI();
}
}//GEN-LAST:event_maxRadiusSliderStateChanged
private void minRadiusSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minRadiusSliderStateChanged
if (minRadiusSlider.getValue() > maxRadiusSlider.getValue()) {
minRadiusSlider.setValue(maxRadiusSlider.getValue());
minRadiusSlider.updateUI();
}
}//GEN-LAST:event_minRadiusSliderStateChanged
private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog(this);
if(result == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
load(file);
} catch (IOException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_loadButtonActionPerformed
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showSaveDialog(this);
if(result == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
save(file);
} catch (IOException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_saveButtonActionPerformed
private void backgroundColorLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_backgroundColorLabelMouseClicked
Color newColor = JColorChooser.showDialog(this,
"Choose Background Color", null);
backgroundColorLabel.setBackground(newColor);
properties.setProperty("background", toHexString(newColor));
}//GEN-LAST:event_backgroundColorLabelMouseClicked
private String toHexString(Color color) {
int rgb = color.getBlue() + (color.getGreen() << 8) +
(color.getRed() << 16);
return "0x" + Integer.toHexString(rgb);
}
private void reset() {
try {
load(new File(""));
} catch (IOException ex) {
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(OptionPanel.class.getName()).log(Level.SEVERE, null, ex);
}
new OptionPanel().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel backgroundColorLabel;
private javax.swing.JTextField ballCountField;
private javax.swing.JSlider expandTimeSlider;
private javax.swing.JTextField explodeCountField;
private javax.swing.JTextField heightField;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JButton loadButton;
private javax.swing.JSlider maxRadiusSlider;
private javax.swing.JSlider maxSpeedSlider;
private javax.swing.JSlider minRadiusSlider;
private javax.swing.JSlider minSpeedSlider;
private javax.swing.JButton saveButton;
private javax.swing.JButton startButton;
private javax.swing.JTextField widthField;
// End of variables declaration//GEN-END:variables
}