瀏覽代碼

Settings now allow custom title and save file names.

master
BinHong Lee 7 年之前
父節點
當前提交
74784513c7
共有 7 個檔案被更改,包括 543 行新增33 行删除
  1. +1
    -0
      .gitignore
  2. +4
    -3
      src/main/java/libsys/Main.java
  3. +33
    -15
      src/main/java/libsys/MainGUI.form
  4. +49
    -15
      src/main/java/libsys/MainGUI.java
  5. +101
    -0
      src/main/java/libsys/Settings.java
  6. +135
    -0
      src/main/java/libsys/SettingsDialog.form
  7. +220
    -0
      src/main/java/libsys/SettingsDialog.java

+ 1
- 0
.gitignore 查看文件

@@ -1,3 +1,4 @@
settings.txt
*.json

.classpath


+ 4
- 3
src/main/java/libsys/Main.java 查看文件

@@ -6,8 +6,9 @@ package libsys;

class Main
{
static String bookFilename = "books.json";
static String userFilename = "users.json";
static Settings settings = new Settings("settings.txt");
static String bookFilename = settings.get("Books Filename");
static String userFilename = settings.get("Users Filename");

public static void main(String[] args)
{
@@ -35,6 +36,6 @@ class Main
handler.users.setUserFileName(userFilename);
}

new MainGUI(handler).setVisible(true);
new MainGUI(handler, settings).setVisible(true);
}
}

+ 33
- 15
src/main/java/libsys/MainGUI.form 查看文件

@@ -52,20 +52,22 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jTabbedPane" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="createBookBtn" min="-2" pref="130" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="createUserBtn" min="-2" pref="130" max="-2" attributes="0"/>
</Group>
<Component id="nameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jTabbedPane" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="nameLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="createBookBtn" min="-2" pref="130" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="createUserBtn" min="-2" pref="130" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="settingsBtn" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -76,10 +78,18 @@
<Component id="nameLabel" min="-2" pref="59" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jTabbedPane" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="createBookBtn" alignment="3" max="32767" attributes="0"/>
<Component id="createUserBtn" alignment="3" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="createBookBtn" alignment="3" max="32767" attributes="0"/>
<Component id="createUserBtn" alignment="3" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="settingsBtn" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -324,7 +334,7 @@
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="36" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Welcome to abc Library"/>
<Property name="text" type="java.lang.String" value="Welcome to the library"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="createBookBtn">
@@ -343,6 +353,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createUserBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="settingsBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Settings"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="settingsBtnActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>


+ 49
- 15
src/main/java/libsys/MainGUI.java 查看文件

@@ -2,17 +2,21 @@ package libsys;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.CountDownLatch;

@SuppressWarnings({"unchecked", "serial"})

public class MainGUI extends javax.swing.JFrame
{
Handler handler;
Settings settings;

public MainGUI(Handler handler)
public MainGUI(Handler handler, Settings settings)
{
this.handler = handler;
this.settings = settings;
initComponents();
nameLabel.setText(settings.get(settings.getKey(0)));
}

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -41,6 +45,7 @@ public class MainGUI extends javax.swing.JFrame
nameLabel = new javax.swing.JLabel();
createBookBtn = new javax.swing.JButton();
createUserBtn = new javax.swing.JButton();
settingsBtn = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

@@ -193,7 +198,7 @@ public class MainGUI extends javax.swing.JFrame
jTabbedPane.addTab("User", userPanel);

nameLabel.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
nameLabel.setText("Welcome to abc Library");
nameLabel.setText("Welcome to the library");

createBookBtn.setText("Add new book");
createBookBtn.addActionListener(new java.awt.event.ActionListener() {
@@ -209,6 +214,13 @@ public class MainGUI extends javax.swing.JFrame
}
});

settingsBtn.setText("Settings");
settingsBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
settingsBtnActionPerformed(evt);
}
});

javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
@@ -216,16 +228,18 @@ public class MainGUI extends javax.swing.JFrame
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(createBookBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(createUserBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(nameLabel))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addComponent(jTabbedPane)
.addContainerGap())
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(nameLabel)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(createBookBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(createUserBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(settingsBtn))))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -234,10 +248,15 @@ public class MainGUI extends javax.swing.JFrame
.addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(createBookBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(createUserBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(createBookBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(createUserBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(settingsBtn)))
.addContainerGap())
);

@@ -298,6 +317,20 @@ public class MainGUI extends javax.swing.JFrame
}
}//GEN-LAST:event_createBookBtnActionPerformed

private void settingsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsBtnActionPerformed
SettingsDialog settingsUI = new SettingsDialog(this, true, settings);
settingsUI.setVisible(true);
if (settingsUI.getReturnStatus() != -1)
{
settings.update(settings.getKey(0), settingsUI.getTitle());
settings.update(settings.getKey(1), settingsUI.getUsersFilename());
settings.update(settings.getKey(2), settingsUI.getBooksFilename());
nameLabel.setText(settingsUI.getTitle());
}
}//GEN-LAST:event_settingsBtnActionPerformed

private void rentBtnActionPerformed(java.awt.event.ActionEvent evt)
{
User thisUser = handler.users.getUser(Integer.parseInt(userSearch.getText()));
@@ -378,6 +411,7 @@ public class MainGUI extends javax.swing.JFrame
private javax.swing.JLabel nameLabel;
private javax.swing.JButton rentBtn;
private javax.swing.JButton returnBtn;
private javax.swing.JButton settingsBtn;
private javax.swing.JLabel userBooks;
private javax.swing.JLabel userID;
private javax.swing.JLabel userLimit;


+ 101
- 0
src/main/java/libsys/Settings.java 查看文件

@@ -0,0 +1,101 @@
package libsys;

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.ArrayList;

public class Settings
{
private HashMap<String, String> items = new HashMap();
private ArrayList<String> keys = new ArrayList();
private String settingsFileName;

public Settings(String settingsFileName)
{
this.settingsFileName = settingsFileName;

try
{
Scanner in = new Scanner(new FileInputStream(settingsFileName));
while (in.hasNextLine())
{
String newInput = in.nextLine();
String[] inputSplitted = newInput.split(":");
keys.add(inputSplitted[0]);
items.put(keys.get(keys.size() - 1), inputSplitted[1]);
}
}
catch (Exception e)
{
System.out.println("Settings file not found!");
setDefault();
}
}

public void toFile()
{
try
{
PrintWriter out = new PrintWriter(settingsFileName);
for (int i = 0; i < keys.size(); i++)
{
out.println(keys.get(i) + ":" + items.get(keys.get(i)));
}
out.close();
}
catch (Exception e)
{
System.out.println(e.getMessage());
setDefault();
}
}

public void update(String key, String newValue)
{
items.remove(key);
items.put(key, newValue);
toFile();
}

public int size()
{
return keys.size();
}

public String getKey(int location)
{
return keys.get(location);
}

public String get(String key)
{
return items.get(key);
}

public void setTitle(String newTitle)
{
update("Title", newTitle);
}

public void setUsersFilename(String newUsersFilename)
{
update("Users Filename", newUsersFilename);
}

public void setBooksFilename(String newBooksFilename)
{
update("Books Filename", newBooksFilename);
}

public void setDefault()
{
keys.add("Title");
items.put(keys.get(0), "Welcome to the library");
keys.add("Users Filename");
items.put(keys.get(1), "users.json");
keys.add("Books Filename");
items.put(keys.get(2), "books.json");
}
}

+ 135
- 0
src/main/java/libsys/SettingsDialog.form 查看文件

@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="saveBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="118" max="32767" attributes="0"/>
<Component id="discardBtn" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="settingsLbl" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="usersFilenameLbl" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="titleLbl" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="booksFilenameLbl" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="booksFilenameTxt" pref="136" max="32767" attributes="0"/>
<Component id="titleTxtField" max="32767" attributes="0"/>
<Component id="usersFilenameTxt" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="settingsLbl" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="titleLbl" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="titleTxtField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="usersFilenameLbl" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="usersFilenameTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="booksFilenameLbl" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="booksFilenameTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="saveBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="discardBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="settingsLbl">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Settings"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="titleLbl">
<Properties>
<Property name="text" type="java.lang.String" value="Title :"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="titleTxtField">
</Component>
<Component class="javax.swing.JLabel" name="usersFilenameLbl">
<Properties>
<Property name="text" type="java.lang.String" value="Users Filename :"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="usersFilenameTxt">
</Component>
<Component class="javax.swing.JLabel" name="booksFilenameLbl">
<Properties>
<Property name="text" type="java.lang.String" value="Books Filename :"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="booksFilenameTxt">
</Component>
<Component class="javax.swing.JButton" name="saveBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Save"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="saveBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="discardBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Discard"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="discardBtnActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

+ 220
- 0
src/main/java/libsys/SettingsDialog.java 查看文件

@@ -0,0 +1,220 @@
package libsys;

/**
*
* @author BinHong Lee
*/
public class SettingsDialog extends javax.swing.JDialog {

/**
* Creates new form SettingsDialog
*/
public SettingsDialog(java.awt.Frame parent, boolean modal, Settings preset) {
super(parent, modal);
initComponents();
setup(preset);
this.preset = preset;
}

/**
* 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() {

settingsLbl = new javax.swing.JLabel();
titleLbl = new javax.swing.JLabel();
titleTxtField = new javax.swing.JTextField();
usersFilenameLbl = new javax.swing.JLabel();
usersFilenameTxt = new javax.swing.JTextField();
booksFilenameLbl = new javax.swing.JLabel();
booksFilenameTxt = new javax.swing.JTextField();
saveBtn = new javax.swing.JButton();
discardBtn = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

settingsLbl.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
settingsLbl.setText("Settings");

titleLbl.setText("Title :");

usersFilenameLbl.setText("Users Filename :");

booksFilenameLbl.setText("Books Filename :");

saveBtn.setText("Save");
saveBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveBtnActionPerformed(evt);
}
});

discardBtn.setText("Discard");
discardBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
discardBtnActionPerformed(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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(saveBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 118, Short.MAX_VALUE)
.addComponent(discardBtn))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(settingsLbl)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(usersFilenameLbl)
.addComponent(titleLbl)
.addComponent(booksFilenameLbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(booksFilenameTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addComponent(titleTxtField)
.addComponent(usersFilenameTxt))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(settingsLbl)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(titleLbl)
.addComponent(titleTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(usersFilenameLbl)
.addComponent(usersFilenameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(booksFilenameLbl)
.addComponent(booksFilenameTxt, 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(saveBtn)
.addComponent(discardBtn))
.addContainerGap())
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed
doClose(1);
}//GEN-LAST:event_saveBtnActionPerformed

private void discardBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discardBtnActionPerformed
doClose(-1);
}//GEN-LAST:event_discardBtnActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SettingsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
SettingsDialog dialog = new SettingsDialog(new javax.swing.JFrame(), true, preset);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}

private void setup(Settings preset)
{
titleTxtField.setText(preset.get(preset.getKey(0)));
usersFilenameTxt.setText((preset.get(preset.getKey(1))));
booksFilenameTxt.setText(preset.get(preset.getKey(2)));
}
private void doClose(int retStatus)
{
returnStatus = retStatus;
title = titleTxtField.getText();
usersFilename = usersFilenameTxt.getText();
booksFilename = booksFilenameTxt.getText();
setVisible(false);
}
public String getTitle()
{
return title;
}
public String getUsersFilename()
{
return usersFilename;
}
public String getBooksFilename()
{
return booksFilename;
}
public int getReturnStatus()
{
return returnStatus;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel booksFilenameLbl;
private javax.swing.JTextField booksFilenameTxt;
private javax.swing.JButton discardBtn;
private javax.swing.JButton saveBtn;
private javax.swing.JLabel settingsLbl;
private javax.swing.JLabel titleLbl;
private javax.swing.JTextField titleTxtField;
private javax.swing.JLabel usersFilenameLbl;
private javax.swing.JTextField usersFilenameTxt;
// End of variables declaration//GEN-END:variables
private int returnStatus;
private String title;
private String usersFilename;
private String booksFilename;
private static Settings preset;
}

Loading…
取消
儲存