📄 virtualcommunity.java
字号:
import domain.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.awt.event.*;
public class VirtualCommunity extends JFrame {
private JTextField fieldName=new JTextField(7);
private JPasswordField fieldPasswd=new JPasswordField(7);
public static Socket socket;
public static BufferedReader in;
public static PrintWriter out;
private String recv;
private int i,j;
private String []swName=new String[20];
JTextField fieldComName=new JTextField(16);
JPasswordField fieldComPasswd=new JPasswordField(16);
JComboBox comboBoxKind;
JTextField fieldComDate=new JTextField(12);
JTextField fieldComCap=new JTextField(12);
JComboBox comboBoxCredit;
JButton bank=new JButton("银行");
JButton investFundCompany=new JButton("软件投资公司");
JButton developmentCompany=new JButton("软件开发公司");
JButton saleCompany=new JButton("软件销售公司");
public VirtualCommunity() throws Exception {
super("欢迎来到虚拟社区!");
JButton JCBox;
JTabbedPane tabbedPane=new JTabbedPane(JTabbedPane.TOP);
getContentPane().add(tabbedPane);
ImageIcon icon=new ImageIcon("72.gif");
JPanel panel1=new JPanel(new BorderLayout());
tabbedPane.addTab("社区主页",null,panel1);
JPanel panel11=new JPanel(new FlowLayout(FlowLayout.RIGHT));
JLabel labelName=new JLabel("用户名");
JLabel labelPasswd=new JLabel("密码:");
JButton register=new JButton("个人注册");
JButton login=new JButton("登陆");
panel11.add(labelName);
panel11.add(fieldName);
panel11.add(labelPasswd);
panel11.add(fieldPasswd);
panel11.add(register);
panel11.add(login);
JPanel panel12=new JPanel(new GridLayout(2,2,4,7));
bank.setEnabled(false);
investFundCompany.setEnabled(false);
developmentCompany.setEnabled(false);
saleCompany.setEnabled(false);
panel12.add(bank);
panel12.add(investFundCompany);
panel12.add(developmentCompany);
panel12.add(saleCompany);
panel1.add(panel11,BorderLayout.NORTH);
panel1.add(panel12,BorderLayout.SOUTH);
JPanel panel2=new JPanel(new BorderLayout());
JPanel panel21=new JPanel(new GridLayout(6,2));
tabbedPane.addTab("公司注册",null,panel2);
JLabel comName=new JLabel("公司名称(登陆用户名):");
JLabel comPasswd=new JLabel("登陆密码(6~12位之间):");
JLabel comKind=new JLabel("公司性质:");
JLabel comDate=new JLabel("注册日期(year/month/day):");
JLabel comCapital=new JLabel("公司资产(万元):");
JLabel comCredit=new JLabel("公司信誉度:");
final String[] comKinds={"Bank","SoftDeveloper","Agent","Investor"};
comboBoxKind=new JComboBox(comKinds);
comboBoxKind.setMaximumRowCount(4);
final String[] comCredits={"★","★★","★★★","★★★★","★★★★★"};
comboBoxCredit=new JComboBox(comCredits);
comboBoxCredit.setMaximumRowCount(5);
panel21.add(comName);
panel21.add(fieldComName);
panel21.add(comPasswd);
panel21.add(fieldComPasswd);
panel21.add(comKind);
panel21.add(comboBoxKind);
panel21.add(comDate);
panel21.add(fieldComDate);
panel21.add(comCapital);
panel21.add(fieldComCap);
panel21.add(comCredit);
panel21.add(comboBoxCredit);
JPanel panel22=new JPanel();
JButton send=new JButton("确定");
panel22.add(send);
panel2.add(panel21,BorderLayout.NORTH);
panel2.add(panel22,BorderLayout.SOUTH);
JPanel panel3=new JPanel();//包括软件待售的信息,从数据库中读取
out.println("Get ForSaleSoftwares");
out.println(" ");
i=Integer.parseInt(in.readLine());
JPanel JP=new JPanel(new BorderLayout());
JPanel JPC=new JPanel();
JPC.setLayout(new GridLayout(1,4,10,10));
JPanel JPD=new JPanel();
JPD.setLayout(new GridLayout(i,4,10,10));
JPC.add(new JLabel("软件名称"));JPC.add(new JLabel("软件价格"));
JPC.add(new JLabel("软件所属种类"));JPC.add(new JLabel("选择购买"));
try{
j=0;
String swType;
String swPrice;
recv=in.readLine();
while(recv.equalsIgnoreCase("END")==false) {
swName[j]=recv;
swType=in.readLine();
swPrice=in.readLine();
JCBox=new JButton(swName[j]);
JPD.add(new JLabel(swName[j]));JPD.add(new JLabel(swPrice));JPD.add(new JLabel(swType));
JPD.add(JCBox);
j++;
recv=in.readLine();
}
System.out.println("j= "+j);
}catch(Exception e) {
System.out.println(e.toString());
}
JP.add(JPC,BorderLayout.NORTH);
JP.add(JPD,BorderLayout.CENTER);
//******************************以上将软件加入面版
tabbedPane.addTab("软件上市信息发布",icon,JP);
//************
JPanel panel4=new JPanel();
tabbedPane.addTab("个人需求信息发布",icon,panel4);
JTextArea jta=new JTextArea(12,40);
jta.setBackground(new Color(159,255,246));
panel4.add(jta);
setBounds(200,200,600,300);
setVisible(true);
register.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String name=fieldName.getText();
String password = fieldPasswd.getText();
try {
socket=new Socket ("192.168.0.200",3000);
in=new BufferedReader(new InputStreamReader(socket.getInputStream() ));
out=new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
out.println("+"+name);
out.flush();
out.println(password);
System.out.println("Registering");
recv=in.readLine();
if(recv.equalsIgnoreCase("1")) {
JOptionPane.showMessageDialog(null,"已有人申请该用户名!请更改用户名!","Error!",
JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(null,"注册新用户成功!","INFORMATION",
JOptionPane.INFORMATION_MESSAGE);
}
catch (Exception e) {
e.toString();
}
}
});
login.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
bank.setEnabled(false);
investFundCompany.setEnabled(false);
developmentCompany.setEnabled(false);
saleCompany.setEnabled(false);
String name=fieldName.getText();
String password = fieldPasswd.getText();
try {
socket=new Socket ("192.168.0.200",3000);
in=new BufferedReader(new InputStreamReader(socket.getInputStream() ));
out=new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
out.println(name);
out.flush();
out.println(password);
System.out.println("Logining...");
recv=in.readLine();
if(recv.equalsIgnoreCase("1")) {
bank.setEnabled(true);
saleCompany.setEnabled(true);
}
else if(recv.equalsIgnoreCase("Bank")) {
bank.setEnabled(true);
}
else if(recv.equalsIgnoreCase("Investor")) {
new InvestFund(name);
}
else if(recv.equalsIgnoreCase("SoftDeveloper"))
new SoftwareDevelopCorp(name);
else if(recv.equalsIgnoreCase("Agent"))
new SoftwareCorp(name);
else
JOptionPane.showMessageDialog(null,"用户名或者密码出错!","Error!",
JOptionPane.ERROR_MESSAGE);
}
catch (Exception e) {
System.out.println(e.toString());
}
}
});
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String name=fieldComName.getText();
String password=fieldComPasswd.getText();
int indexKind=comboBoxKind.getSelectedIndex();
String character=comKinds[indexKind];
String date=fieldComDate.getText();
String capital=fieldComCap.getText();
int indexCredit=comboBoxCredit.getSelectedIndex();
String credit=comCredits[indexCredit];
try {
socket=new Socket ("192.168.0.200",3000);
in=new BufferedReader(new InputStreamReader(socket.getInputStream() ));
out=new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
out.println("$"+name);
out.println(password);
out.println(character);
out.println(date);
out.println(capital);
out.println(credit);
recv=in.readLine();
if(recv.equalsIgnoreCase("1")) {
System.out.println("已有人申请该用户名!请更改用户名!");
}
else
JOptionPane.showMessageDialog(null,"注册新公司成功!","INFORMATION",
JOptionPane.INFORMATION_MESSAGE);
}catch (Exception e) {System.out.println(e.toString());}
}
});
bank.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
new EnterBankGUI();
}
});
saleCompany.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
try {
new SoftwareCorp();
}catch(Exception e) {
System.out.println(e.toString());
}
}
});
}
public static void main(String[] args) throws Exception {
try {
socket=new Socket ("192.168.0.200",3000);
in=new BufferedReader(new InputStreamReader(socket.getInputStream() ));
out=new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),true);
VirtualCommunity vc=new VirtualCommunity();
vc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}catch (IOException e) {
System.out.println(e.toString() );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -