- 论坛徽章:
- 0
|
- void jButton1_actionPerformed(ActionEvent e) {
- username = jTextField1.getText();
- password = jPasswordField1.getText();
- try {
- s = new Socket(host, 10000); //与服务器端建立连接
- InputStreamReader isr;
- //从服务器读取数据接口
- isr = new InputStreamReader(s.getInputStream());
- br = new BufferedReader(isr);
- pw = new PrintWriter(s.getOutputStream(), true);
- pw.println("Login");
- pw.println(username);
- pw.println(password);
- String line = null;
- if ( (line = br.readLine()) != null) {
- if (line.startsWith(">>>loginSuccess")) {
- success = true;
- }
- else {
- success = false;
- }
- }
- br.readLine();
- }
- catch (IOException ie) {
- System.out.println("error: " + ie.toString());
- }
- finally {
- try {
- if (br != null) {
- br.close();
- }
- if (pw != null) {
- pw.close();
- }
- if (s != null) {
- s.close();
- }
- }
- catch (IOException oe) {
- }
- }
- if (success) {
- this.setVisible(false);
- this.dispose();
- ShopClientFrame frame = null;
- frame = new ShopClientFrame(host);
- frame.validate();
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- Dimension frameSize = frame.getSize();
- if (frameSize.height > screenSize.height) {
- frameSize.height = screenSize.height;
- }
- if (frameSize.width > screenSize.width) {
- frameSize.width = screenSize.width;
- }
- frame.setLocation( (screenSize.width - frameSize.width) / 2,
- (screenSize.height - frameSize.height) / 2);
- frame.setVisible(true);
- frame.now();//标志1
- }
- else {
- d1 = new Dialog(this, "警告", true);
- Panel p1 = new Panel();
- p1.add(new Label("您无权进本系统!"));
- Panel p2 = new Panel();
- p2.add(jButton3);
- d1.add("South", p2);
- d1.add("Center", p1);
- d1.setSize(200, 100);
- d1.setLocation(400, 400);
- d1.show();
- }
- System.out.println(username);
- System.out.println(password);
- }
复制代码
如上代码。。为一个按钮的动作。。(登录过程)
登录成功关闭此窗口。。实例化一个登录后的窗口。。
问题是在如上所示标志1处。。调用now()方法后。frame就不能显示上面的组件了(为什么?)
now()方法{
其中有一个阻塞函数
}
怎么解决?
帮我!! |
|