📄 settingsscreen.java
字号:
/*
* RIC 2 by Harry Otten (c) Copyright 2003 hotten@dds.nl
* Check out http://www.hotten.dds.nl/ric/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SettingsScreen extends JFrame implements ActionListener, WindowListener {
private Config config;
private MainScreenGUI mainScreenGUI;
private JButton save, cancel;
private JTextField PassWordTextField, hostTextField, hostPortTextField, UserNameTextField;
private JComboBox youAreConnectedComboBox, nobodyConnectedComboBox,
someoneConnectedComboBox, youAndMoreComboBox;
private JCheckBox hideOrNotCheckBox, ignoreMessagesCheckBox, soundEnabledCheckBox;
public SettingsScreen(Config config, MainScreenGUI mainScreenGUI) {
this.config=config;
this.mainScreenGUI=mainScreenGUI;
}
public void setup() {
save = new JButton();
cancel = new JButton();
PassWordTextField = new JTextField();
hostTextField = new JTextField();
hostPortTextField = new JTextField();
UserNameTextField = new JTextField();
youAreConnectedComboBox = new JComboBox();
nobodyConnectedComboBox = new JComboBox();
someoneConnectedComboBox = new JComboBox();
youAndMoreComboBox = new JComboBox();
JLabel hostLabel = new JLabel("Server IP Adres");
JLabel hostPortLabel = new JLabel("TCP Port");
JLabel UserNameLabel = new JLabel("Username");
JLabel PassWordLabel = new JLabel("Password");
JLabel youAreConnectedLabel = new JLabel();
JLabel nobodyConnectedLabel = new JLabel();
JLabel someoneConnectedLabel = new JLabel();
JLabel youAndMoreLabel = new JLabel();
hideOrNotCheckBox = new JCheckBox("Hide window from taskbar");
ignoreMessagesCheckBox = new JCheckBox("Ignore Messages");
soundEnabledCheckBox = new JCheckBox("Sound Enabled");
this.getContentPane().setLayout(null);
save.addActionListener(this);
cancel.addActionListener(this);
hostLabel.setBounds(0,0,125,20);
hostPortLabel.setBounds(0,20,125,20);
UserNameLabel.setBounds(0,40,125,20);
PassWordLabel.setBounds(0,60,125,20);
hostTextField.setBounds(125,0,125,20);
hostPortTextField.setBounds(125,20,125,20);
UserNameTextField.setBounds(125,40,125,20);
PassWordTextField.setBounds(125,60,125,20);
youAreConnectedLabel.setBounds(260,0,125,20);
nobodyConnectedLabel.setBounds(260,20,125,20);
someoneConnectedLabel.setBounds(260,40,125,20);
youAndMoreLabel.setBounds(260,60,125,20);
hideOrNotCheckBox.setBounds(0,80,240,20);
ignoreMessagesCheckBox.setBounds(250,80,250,20);
soundEnabledCheckBox.setBounds(0,100,240,20);
youAreConnectedComboBox.setBounds(385,0,100,20);
nobodyConnectedComboBox.setBounds(385,20,100,20);
someoneConnectedComboBox.setBounds(385,40,100,20);
youAndMoreComboBox.setBounds(385,60,100,20);
save.setBounds(90,125,80,25);
cancel.setBounds(340,125,80,25);
this.getContentPane().add(hostLabel);
this.getContentPane().add(UserNameLabel);
this.getContentPane().add(PassWordLabel);
this.getContentPane().add(hostPortLabel);
this.getContentPane().add(hostTextField);
this.getContentPane().add(UserNameTextField);
this.getContentPane().add(hostPortTextField);
this.getContentPane().add(PassWordTextField);
this.getContentPane().add(youAreConnectedLabel);
this.getContentPane().add(nobodyConnectedLabel);
this.getContentPane().add(someoneConnectedLabel);
this.getContentPane().add(youAndMoreLabel);
this.getContentPane().add(hideOrNotCheckBox);
this.getContentPane().add(ignoreMessagesCheckBox);
this.getContentPane().add(soundEnabledCheckBox);
this.getContentPane().add(youAreConnectedComboBox);
this.getContentPane().add(nobodyConnectedComboBox);
this.getContentPane().add(someoneConnectedComboBox);
this.getContentPane().add(youAndMoreComboBox);
this.getContentPane().add(save);
this.getContentPane().add(cancel);
cancel.setText("Cancel");
save.setText("Save");
youAreConnectedLabel.setText("you are connected");
nobodyConnectedLabel.setText("nobody connected");
someoneConnectedLabel.setText("someone connected");
youAndMoreLabel.setText("you and more");
fillBox(youAreConnectedComboBox);
fillBox(nobodyConnectedComboBox);
fillBox(someoneConnectedComboBox);
fillBox(youAndMoreComboBox);
setIconImage(new ImageIcon("../graphics/network.gif").getImage());
setTitle("Settings");
setResizable(false);
setSize(500,185);
addWindowListener(this);
}
public void GUI()
{
// Make sure the windows is getting placed next to the mainscreen.
Point p = mainScreenGUI.getLocationOnScreen();
double resolutieX = (((Toolkit.getDefaultToolkit()).getScreenSize()).getWidth());
Dimension d = mainScreenGUI.getSize();
// make sure when the setting screen would be placed of screen it will
// place it to the left instead of right.
if ((p.getX()+d.getWidth()+this.getWidth())>resolutieX)
p.setLocation(p.getX()-this.getWidth(),p.getY());
else p.setLocation(p.getX()+d.getWidth(),p.getY());
setLocation(p);
// Read the value's into the textfields
hostTextField.setText(config.getHost());
hostPortTextField.setText((new Integer(config.getHostPort()).toString()));
UserNameTextField.setText(config.getUserName());
PassWordTextField.setText(config.getPassWord());
youAreConnectedComboBox.setSelectedItem(config.getWeAreConnectedColor());
nobodyConnectedComboBox.setSelectedItem(config.getNobodyConnectedColor());
someoneConnectedComboBox.setSelectedItem(config.getSomeonConnectedColor());
youAndMoreComboBox.setSelectedItem(config.getMoreConnectedColor());
if (config.getHideFromTaskbar())
hideOrNotCheckBox.setSelected(true);
else hideOrNotCheckBox.setSelected(false);
if (config.getIgnoreMessages())
ignoreMessagesCheckBox.setSelected(true);
else ignoreMessagesCheckBox.setSelected(false);
if (config.getSoundEnabled())
soundEnabledCheckBox.setSelected(true);
else soundEnabledCheckBox.setSelected(false);
show();
}
private void fillBox(JComboBox comboBox) {
String rood = "Red";
String groen = "Green";
String blauw = "Blue";
String paars = "Purple";
comboBox.addItem(rood);
comboBox.addItem(blauw);
comboBox.addItem(groen);
comboBox.addItem(paars);
}
public void windowActivated(WindowEvent event)
{};
public void windowClosed(WindowEvent event)
{};
public void windowClosing(WindowEvent event)
{
dispose();
};
public void windowDeactivated(WindowEvent event)
{};
public void windowDeiconified(WindowEvent event)
{};
public void windowIconified(WindowEvent event)
{};
public void windowOpened(WindowEvent event)
{};
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == save)
{
config.setHost(hostTextField.getText());
config.setHostPort((Integer.parseInt(hostPortTextField.getText())));
config.setUserName(UserNameTextField.getText());
config.setPassWord(PassWordTextField.getText());
config.setWeAreConnectedColor( (String) (youAreConnectedComboBox.getSelectedItem()) );
config.setNobodyConnectedColor( (String) (nobodyConnectedComboBox.getSelectedItem()) );
config.setSomeonConnectedColor( (String) (someoneConnectedComboBox.getSelectedItem()) );
config.setMoreConnectedColor( (String) (youAndMoreComboBox.getSelectedItem()) );
config.setHideFromTaskbar(hideOrNotCheckBox.isSelected());
config.setIgnoreMessages(ignoreMessagesCheckBox.isSelected());
config.setSoundEnabled(soundEnabledCheckBox.isSelected());
config.writeSettings();
}
// Cancel or save, whatevery get the window off the screen
dispose();
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -