⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setaddr.java

📁 Java+Eclipse+Mysql的局域网聊天程序源代码
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

import java.awt.event.*;
import java.awt.Insets;
import java.awt.GridBagConstraints;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JTextPane;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import javax.swing.JTextField;

public class SetAddr extends JPanel implements ActionListener{

	private static final long serialVersionUID = 1L;
	private JPanel jPanel = null;
	private JLabel jLabel = null;
	private JTextField jf_addr = null;
	private JTextField jf_port = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JButton btn_Save = null;
	private JButton btn_Back = null;
	
	private JPanel jp=null;
	private JPanel jPanel1 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel alert = null;
	private JLabel jLabel5 = null;
	private JTextField jf_localport = null;
	/**
	 * This is the default constructor
	 */
	public SetAddr(JPanel jp) {
		super();
		this.jp=jp;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel4 = new JLabel();
		jLabel4.setText("");
		jLabel4.setPreferredSize(new Dimension(300, 100));
		jLabel4.setBackground(Color.white);
		jLabel4.setIcon(new ImageIcon(getClass().getResource("/top.PNG")));
		this.setSize(451, 295);
		this.setLayout(new BorderLayout());
		this.add(getJPanel(), BorderLayout.CENTER);
		this.add(getJPanel1(), BorderLayout.BEFORE_LINE_BEGINS);
		this.add(jLabel4, BorderLayout.NORTH);
		
		ReadConfig rc=new ReadConfig();
		jf_addr.setText(rc.getString("addr", false));
		jf_port.setText(rc.getString("port", false));
		jf_localport.setText(rc.getString("lpor", false));
		rc.closeRC();
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
			gridBagConstraints22.fill = GridBagConstraints.BOTH;
			gridBagConstraints22.gridy = 6;
			gridBagConstraints22.weightx = 1.0;
			gridBagConstraints22.insets = new Insets(2, 0, 5, 10);
			gridBagConstraints22.gridwidth = 2;
			gridBagConstraints22.gridx = 4;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.gridx = 3;
			gridBagConstraints12.insets = new Insets(0, 20, 5, 0);
			gridBagConstraints12.gridy = 6;
			jLabel5 = new JLabel();
			jLabel5.setText("本机端口:");
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.gridx = 4;
			gridBagConstraints11.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints11.insets = new Insets(0, 0, 15, 0);
			gridBagConstraints11.gridy = 0;
			alert = new JLabel();
			alert.setText(" ");
			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
			gridBagConstraints41.gridx = 4;
			gridBagConstraints41.gridy = 9;
			GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
			gridBagConstraints31.gridx = 3;
			gridBagConstraints31.fill = GridBagConstraints.NONE;
			gridBagConstraints31.gridy = 9;
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 2;
			gridBagConstraints21.gridwidth = 2;
			gridBagConstraints21.insets = new Insets(0, 0, 15, 0);
			gridBagConstraints21.fill = GridBagConstraints.NONE;
			gridBagConstraints21.gridy = 0;
			jLabel2 = new JLabel();
			jLabel2.setText("用户设置");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 3;
			gridBagConstraints1.insets = new Insets(0, 20, 5, 0);
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints1.gridy = 5;
			jLabel1 = new JLabel();
			jLabel1.setText("连接端口:");
			jLabel1.setAlignmentY(20.0F);
			jLabel1.setAlignmentX(20.0F);
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints3.gridy = 5;
			gridBagConstraints3.weightx = 1.0;
			gridBagConstraints3.gridwidth = 2;
			gridBagConstraints3.insets = new Insets(2, 0, 5, 10);
			gridBagConstraints3.gridx = 4;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints2.gridy = 3;
			gridBagConstraints2.weightx = 1.0;
			gridBagConstraints2.gridwidth = 1;
			gridBagConstraints2.insets = new Insets(0, 0, 10, 10);
			gridBagConstraints2.gridx = 4;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 3;
			gridBagConstraints.insets = new Insets(0, 20, 5, 0);
			gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints.gridy = 3;
			jLabel = new JLabel();
			jLabel.setText("连接地址:");
			jLabel.setAlignmentY(20.0F);
			jLabel.setAlignmentX(20.0F);
			jPanel = new JPanel();
			jPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
			jPanel.setLayout(new GridBagLayout());
			jPanel.setBackground(Color.white);
			jPanel.add(jLabel, gridBagConstraints);
			jPanel.add(getJf_addr(), gridBagConstraints2);
			jPanel.add(getJf_port(), gridBagConstraints3);
			jPanel.add(jLabel1, gridBagConstraints1);
			jPanel.add(jLabel2, gridBagConstraints21);
			jPanel.add(getBtn_Save(), gridBagConstraints31);
			jPanel.add(getBtn_Back(), gridBagConstraints41);
			jPanel.add(alert, gridBagConstraints11);
			jPanel.add(jLabel5, gridBagConstraints12);
			jPanel.add(getJf_localport(), gridBagConstraints22);
		}
		return jPanel;
	}

	/**
	 * This method initializes jf_addr	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJf_addr() {
		if (jf_addr == null) {
			jf_addr = new JTextField();
			jf_addr.setPreferredSize(new Dimension(100, 22));
			jf_addr.setAlignmentY(20.0F);
			jf_addr.setHorizontalAlignment(JTextField.LEFT);
			jf_addr.setText("");
			jf_addr.setEditable(true);
			jf_addr.setAlignmentX(20.0F);
		}
		return jf_addr;
	}

	/**
	 * This method initializes jf_port	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJf_port() {
		if (jf_port == null) {
			jf_port = new JTextField();
			jf_port.setMinimumSize(new Dimension(80, 22));
			jf_port.setAlignmentX(20.0F);
			jf_port.setAlignmentY(20.0F);
			jf_port.setPreferredSize(new Dimension(100, 22));
		}
		return jf_port;
	}

	/**
	 * This method initializes jCheckBox1	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */

	private JButton getBtn_Save() {
		if (btn_Save == null) {
			btn_Save = new JButton();
			btn_Save.setText("保存");
			btn_Save.addActionListener(this);
		}
		return btn_Save;
	}

	/**
	 * This method initializes btn_Back	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtn_Back() {
		if (btn_Back == null) {
			btn_Back = new JButton();
			btn_Back.addActionListener(this);
			btn_Back.setText("返回");
		}
		return btn_Back;
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==btn_Back)
		{
			this.setVisible(false);
			jp.setVisible(true);
		}
		else if(e.getSource()==btn_Save)
		{
			ReadConfig rc=new ReadConfig();
			
			rc.SaveConfig("addr", jf_addr.getText(), false);
			rc.SaveConfig("port", jf_port.getText(), false);
			rc.SaveConfig("lpor", jf_localport.getText(), false);
			rc.closeRC();
		
			this.setVisible(false);
			jp.setVisible(true);
		}
		
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.insets = new Insets(0, 0, 0, 0);
			jLabel3 = new JLabel();
			jLabel3.setText("");
			jLabel3.setAlignmentX(1.0F);
			jLabel3.setPreferredSize(new Dimension(130, 200));
			jLabel3.setIcon(new ImageIcon(getClass().getResource("/QQ.png")));
			jPanel1 = new JPanel();
			jPanel1.setLayout(new GridBagLayout());
			jPanel1.setBackground(Color.white);
			jPanel1.add(jLabel3, gridBagConstraints6);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jf_localport	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJf_localport() {
		if (jf_localport == null) {
			jf_localport = new JTextField();
		}
		return jf_localport;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -