读书人

身在瑞典求救!很基础的有关问题有关

发布时间: 2012-01-15 22:57:49 作者: rapoo

身在瑞典求救!很基础的问题,有关linux平台上用java做一个C/S系统
跑到这里来交流,以前在上海学的是MIS,然后在这边选了门internet technology,觉得无从下手阿!有一个最关键的实验是:
Design and implement a server application which acts as an Internet bank, i.e. keeps track of bank accounts and allows clients to connect over the Internet and make deposits and withdrawals from any of the bank accounts. Also implement the client application. Use any port number available for general use, i.e. in the range 50000 through 65535.
简单来说就是用Java做一个C/S结构的“银行”系统,只要能取钱存钱就行。
然后还有以下要求:
1. The server and client should be written in Java1 and should run under Linux. Linux computers are available in the course laboratory. Coding may of course be carried out on any computer platform of your choice.
2. The applications should communicate through TCP.
3. The server must be able to handle several clients simultaneously. In Java, this is easiest done by making the server multithreaded.
4. For simplicity, the server need only keep track of ten (10) bank accounts, numbered 0 through 9.
5. The amount of money (balance, amount withdrawn/deposited) should be of type integer.
6. The server should register in the bank account record the IP address of the host that made the last transaction. These IP addresses should be printed by the server on screen along with the account number and account balance after each transaction.
7. You must make sure that several clients, each corresponding to a different server thread, cannot update the same account simultaneously. In Java, this can be done easily by using the synchronized keyword.
简单来说就是必须是tcp通信,多用户可以同时处理,等等。
问题是本人没有学过java,所以无从下手阿!google了相关内容,但是都是一大堆材料,抓不住核心。在这里提这个问题肯定很幼稚了,但是希望哪一位能给一些一针见血的提示,或是哪位有类似的范例。我在这里多谢了!!!

[解决办法]
瑞典理工学院计算机水平众所周知很高,
你来这里问,还真不如找个当地的学生帮你解决.
而且他们他们代码的效率通常很高!!!
[解决办法]
没学过 Java?那就真的郁闷了。慢慢学吧,希望你有的是时间。
[解决办法]
事务处理的例子。

设置两个数据库。

BankA
BankB

两个数据库都具有各自的表“账务”:

3编号int40 主键
0姓名varchar501
0金额money81


二、无事务的情况

import java.awt.*;
import .swing.*;

import java.io.*;
import java.sqljava.awt.event.*;


import javax.*;
public class TransactionFrame extends JFrame {

JPanel contentPane;
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextField jTextField3 = new JTextField();
JTextPane jTextPane1 = new JTextPane();
JTextPane jTextPane2 = new JTextPane();
JTextPane jTextPane3 = new JTextPane();

java.sql.Connection conn1= null;
java.sql.Statement stmt1 =null;
java.sql.ResultSet rs1=null;

java.sql.Connection conn2= null;
java.sql.Statement stmt2 =null;
java.sql.ResultSet rs2=null;

//构造函数
public TransactionFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

//执行入口函数
public static void main(String[] args) {

TransactionFrame frame = new TransactionFrame();
frame.setVisible(true);
}

//控件初始化方法
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jTextField1.setText( "1 ");
jTextField1.setBounds(new Rectangle(31, 62, 105, 25));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle( "Frame Title ");
jTextField2.setText( "1 ");
jTextField2.setBounds(new Rectangle(243, 62, 105, 25));
jButton1.setBounds(new Rectangle(147, 41, 81, 23));
jButton1.setText( "A > B ");
jButton1.addActionListener(new
Frame1_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(146, 81, 81, 23));
jButton2.setText( "A < B ");
jButton2.addActionListener(new
Frame1_jButton2_actionAdapter(this));
jTextField3.setText( "0 ");
jTextField3.setBounds(new Rectangle(132, 116, 116, 20));
jTextPane1.setText( "jTextPane1 ");
jTextPane1.setBounds(new Rectangle(32, 175, 128, 25));
jTextPane2.setText( "jTextPane2 ");
jTextPane2.setBounds(new Rectangle(220, 172, 128, 25));
jTextPane3.setText( "jTextPane3 ");
jTextPane3.setBounds(new Rectangle(32, 220, 318, 25));
contentPane.add(jTextField1, null);
contentPane.add(jTextField2, null);
contentPane.add(jButton1, null);
contentPane.add(jButton2, null);
contentPane.add(jTextField3, null);
contentPane.add(jTextPane1, null);
contentPane.add(jTextPane2, null);
contentPane.add(jTextPane3, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}




[解决办法]
用hibernate来做数据库,就可以很容易的做事务处理了。
[解决办法]
楼主以前用什么语言?
[解决办法]
google
[解决办法]
不错
[解决办法]
是不是该结贴了?

读书人网 >J2SE开发

热点推荐