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

📄 mainmenu.java

📁 本工程模拟网上社区,其中包括银行,软件销售公司,软件投资公司,茶餐馆,和多个服务器.
💻 JAVA
字号:
package softwarecompanyclient;

import java.net.URL;
import java.awt.image.*;
import java.applet.*;

import client.*;
import java.awt.Dimension;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.event.*;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.SystemColor;
import java.util.Vector;
import java.awt.Color;
import java.awt.Rectangle;
import java.net.Socket;
import java.io.PrintWriter;
import java.io.*;
import java.util.StringTokenizer;
import java.awt.Font;

public class MainMenu extends JFrame implements ListSelectionListener{
    private Socket socket;
    private DataInputStream in;
    private DataOutputStream out;
    private String str;
    private String [][]text;
    private Company aCompany;
    private Hall hall;
    private String IP;
    JPanel contentPane;
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JList companyList = new JList();
    JTextArea companyInfoTArea = new JTextArea();
    JButton loginButton = new JButton();
    JButton enterButton = new JButton();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    FlowLayout flowLayout1 = new FlowLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    JButton returnButton = new JButton();
    ImageIcon returnImage = new ImageIcon("return.png");
    ///////////////////////////////////////////////////
    ImageIcon background = new ImageIcon("loadingscreen.jpg");
    JLabel imageLabel = new JLabel();

    public MainMenu(Hall hall_,String IP_) {
        hall=hall_;
        IP=IP_;
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
            socket = new Socket(IP, 4009);
            in = new DataInputStream(socket.getInputStream());
            out = new DataOutputStream(socket.getOutputStream());
            out.writeUTF("1");
            str= in.readUTF();
            StringTokenizer st = new StringTokenizer(str, "/");
            String s = st.nextToken();
            int i = Integer.parseInt(s);
            text = new String[i][6];
            for (int j = 0; j < i; j++)
            {
                for (int k = 0; k < 6; k++) {
                    text[j][k] = st.nextToken();
                }
            }
            Vector companys, companyNames;
            companyNames = new Vector();
            for (int j = 0; j < i; j++) {
                companyNames.add(text[j][0]);
            }
            companyList = new JList(companyNames);
            companyList.addListSelectionListener(this);
            jScrollPane1.getViewport().setView(companyList);
            companyList.updateUI();

        } catch (Exception exception) {
            exception.printStackTrace();
        }
        init();
    }

    private void jbInit() throws Exception {
        imageLabel.setIcon(background);
        imageLabel.setBounds(new Rectangle(1, 0, 506, 310));
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(null);
        setSize(new Dimension(508, 345));
        setTitle("软件公司主页");
        jLabel1.setText("现有公司:");
        jLabel1.setBounds(new Rectangle(62, 26, 76, 15));
        contentPane.setToolTipText("");
        jLabel2.setText("公司简介:");
        jLabel2.setBounds(new Rectangle(222, 26, 68, 15));
        companyInfoTArea.setBackground(SystemColor.text);
        companyInfoTArea.setOpaque(false);
        companyInfoTArea.setText("请选择公司");
        companyInfoTArea.setLineWrap(true);
        companyInfoTArea.setBounds(new Rectangle(223, 54, 172, 129));
        loginButton.setBackground(UIManager.getColor("Panel.background"));
        loginButton.setText("注册新公司");
        loginButton.addActionListener(new MainMenu_jButton1_actionAdapter(this));
        enterButton.setBackground(UIManager.getColor("Panel.background"));
        enterButton.setActionCommand("登录公司");
        enterButton.setText("登录公司");
        enterButton.addActionListener(new MainMenu_enterButton_actionAdapter(this));
        jPanel2.setLayout(flowLayout1);
        jPanel1.setLayout(null);
        jScrollPane1.getViewport().setBackground(UIManager.getColor(
                "TextArea.background"));
        jScrollPane1.setOpaque(false);
        jScrollPane1.setVerifyInputWhenFocusTarget(false);
        jScrollPane1.setBounds(new Rectangle(62, 56, 100, 129));
        companyList.setBackground(UIManager.getColor("TextArea.background"));
        companyList.setDoubleBuffered(true);
        companyList.setOpaque(false);
        companyList.setSelectionForeground(Color.orange);
        companyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        returnButton.setBackground(SystemColor.control);
        returnButton.setBounds(new Rectangle(258, 272, 139, 30));
        returnButton.setFont(new java.awt.Font("华文行楷", Font.BOLD, 14));
        returnButton.setForeground(Color.red);
        returnButton.setIcon(returnImage);
        returnButton.setText("返回社区");
        returnButton.addActionListener(new MainMenu_returnButton_actionAdapter(this));
        jPanel1.setOpaque(false);
        jPanel1.setToolTipText("");
        jPanel1.setBounds(new Rectangle(1, 0, 508, 216));
        jPanel2.setBackground(Color.orange);
        jPanel2.setOpaque(false);
        jPanel2.setBounds(new Rectangle(82, 232, 299, 35));
        jPanel2.add(enterButton);
        jPanel2.add(loginButton);
        jScrollPane1.getViewport().add(companyList);

        contentPane.add(jPanel1, null);
        contentPane.add(imageLabel, null);
        contentPane.add(returnButton, null);
        contentPane.add(jPanel2, null);
        jPanel1.add(jLabel2, null);
        jPanel1.add(jScrollPane1, null);
        jPanel1.add(jLabel1, null);
        jPanel1.add(companyInfoTArea, null);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        newCompanyDialog ncompanydialog = new newCompanyDialog(socket,this);
        this.setVisible(false);
    }

    public void enterButton_actionPerformed(ActionEvent e) {
        int index = companyList.getSelectedIndex();
        if(index <0)
            JOptionPane.showMessageDialog(this,"请选择一个公司!");
        else
        {
            aCompany = new Company(text[index][0],text[index][1],text[index][2],text[index][3],text[index][4],text[index][5]);
            swCompanyDialog companyDialog = new swCompanyDialog(socket,aCompany,this);
            this.setVisible(false);
        }
    }
    public void init()
    {
        imageLabel.setVisible(true);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth  = screenSize.width;
        int screenHeight = screenSize.height;
        Dimension frameSize = this.getSize();
        int x = (screenWidth - frameSize.width)/2;
        int y = (screenHeight - frameSize.height)/2;

        this.setLocation(x,y);
        this.setVisible(true);
    }

    public void valueChanged(ListSelectionEvent e)
    {
        int index = companyList.getSelectedIndex();
        String info = text[index][5];
        companyInfoTArea.setText(info);
    }


    public void returnButton_actionPerformed(ActionEvent e) {
        hall.setVisible(true);
        hall=null;
        try{
            out.writeUTF("0");
            out.flush();
            in.close();
            out.close();
            socket.close();
        }catch(IOException ex)
        {
            System.out.println("e"+ex.toString());
        }
        this.dispose();
    }
}


class MainMenu_returnButton_actionAdapter implements ActionListener {
    private MainMenu adaptee;
    MainMenu_returnButton_actionAdapter(MainMenu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.returnButton_actionPerformed(e);
    }
}


class MainMenu_enterButton_actionAdapter implements ActionListener {
    private MainMenu adaptee;
    MainMenu_enterButton_actionAdapter(MainMenu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.enterButton_actionPerformed(e);
    }
}


class MainMenu_jButton1_actionAdapter implements ActionListener {
    private MainMenu adaptee;
    MainMenu_jButton1_actionAdapter(MainMenu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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