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

📄 inputip.java~23~

📁 这是一个用jbuilder2005编写的图书管理系统
💻 JAVA~23~
字号:
package bookmanage;

import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.io.*;

/**
 * <p>Title: 图书管理系统</p>
 *
 * <p>Description: 此类是继承JDialog,用来输入数据库服务器的IP地址</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: 浙江工业大学信息学院计算机系</p>
 *
 * @author 曾文秋
 * @version 1.0
 * @todo 删除SQLName和SQLPassword的默认值
 */
public class InputIp
    extends JFrame {
  public InputIp() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public static String IP="localhost";
  public static String SQLName="zwq";
  public static String SQLPassword="zengwenqiu";
  public static String Port="1433";
  JPanel jPanel1 = new JPanel();
  Border border1 = BorderFactory.createLineBorder(UIManager.getColor(
      "ToolBar.darkShadow"), 2);
  Border border2 = new TitledBorder(border1, "请在下面输入数据库服务器的IP地址");
  JLabel jLabel1 = new JLabel();
  JTextField jTextFieldIP = new JTextField();
  JButton jButtonIPAlert = new JButton();
  JButton jButtonIPCancel = new JButton();
  JLabel jLabel4 = new JLabel();
  JTextField jTextFieldDuanKouHao = new JTextField();


  private void jbInit() throws Exception {
    border2 = new TitledBorder(BorderFactory.createLineBorder(Color.lightGray,
        2), "请在下面输入数据库服务器的相关信息");
    this.getContentPane().setLayout(null);
    jPanel1.setBorder(border2);
    jPanel1.setBounds(new Rectangle(59, 22, 280, 122));
    jPanel1.setLayout(null);
    jTextFieldIP.setText("localhost");
    jTextFieldIP.setBounds(new Rectangle(122, 28, 108, 22));
    jButtonIPAlert.setBounds(new Rectangle(83, 163, 81, 23));
    jButtonIPAlert.setText("确定输入");
    jButtonIPAlert.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonIPAlert_actionPerformed(e);
      }
    });
    jButtonIPCancel.setBounds(new Rectangle(219, 164, 81, 23));
    jButtonIPCancel.setText("取消");
    jButtonIPCancel.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonIPCancel_actionPerformed(e);
      }
    });
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setResizable(false);
    jLabel4.setText("端口号:");
    jLabel4.setBounds(new Rectangle(22, 66, 91, 20));
    jTextFieldDuanKouHao.setText("1433");
    jTextFieldDuanKouHao.setBounds(new Rectangle(122, 66, 108, 22));
    jPanel1.add(jLabel1);
    jPanel1.add(jTextFieldIP);
    jPanel1.add(jLabel4);
    jPanel1.add(jTextFieldDuanKouHao);
    this.getContentPane().add(jButtonIPCancel);
    this.getContentPane().add(jButtonIPAlert);
    this.getContentPane().add(jPanel1);
    jLabel1.setBounds(new Rectangle(22, 28, 77, 20));
    jLabel1.setText("服务器地址:");
    try{
      File f=new File("lib.txt");
      FileReader fr=new FileReader(f);
      BufferedReader br=new BufferedReader(fr);
      IP=br.readLine();
      if(IP!=null){
        IP=IP.trim();
      }
      else{
        IP="";
      }
      SQLName=br.readLine();
      if(SQLName!=null){
        SQLName=SQLName.trim();
      }
      else {
        SQLName="";
      }
      Port=br.readLine();
      if(Port!=null){
        Port=Port.trim();
      }
      else{
        Port="";
      }
      jTextFieldIP.setText(IP);
      jTextFieldDuanKouHao.setText(Port);
      br.close();
    }catch(Exception ee){
      ee.printStackTrace();
    }
  }

  public void jButtonIPCancel_actionPerformed(ActionEvent e) {
    this.dispose();
  }

  public void jButtonIPAlert_actionPerformed(ActionEvent e) {
    IP=jTextFieldIP.getText().trim();
    SQLPassword=new String().trim();
    Port=jTextFieldDuanKouHao.getText().trim();
    try{
      File f=new File("lib.txt");
      FileWriter fw=new FileWriter(f);
      BufferedWriter bw=new BufferedWriter(fw);
      bw.write(IP);bw.newLine();
      bw.write(SQLName);bw.newLine();
      bw.write(Port);bw.newLine();
      bw.close();
      fw.close();

    }catch(Exception ee){
      ee.printStackTrace();
    }

    this.dispose();
    MainFrame mf=new MainFrame();
    mf.setLocation(200,100);
    mf.setSize(700,450);
    //mf.setBounds(0,0,1024,768);
    mf.setVisible(true);
  }
}

⌨️ 快捷键说明

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