/**
 * 
 */
package com.softfz.zxj;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
 
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JWindow;
 
/**
 * @author a
 *
 */
public class Client extends JFrame{

private static final Client client = new Client();

Container ct = this.getContentPane();
private JFrame recordFrame = new JFrame();
//private JWindow recordFrame = new JWindow();
private JPanel basePanel = new JPanel(new BorderLayout());
private JPanel headPanel = new JPanel(new BorderLayout());
private JPanel centrePanel = new JPanel(); 
private JPanel bottomPanel = new JPanel(new BorderLayout());

//private JLabel portraitLabel = new JLabel(new ImageIcon("image\\Login.gif"));

private JScrollPane bottomPane= new JScrollPane();
private JTextPane recordPane = new JTextPane();

private boolean status = false;
private JButton recordBtn = new JButton("fff");


/**
 * @param args
 */
public static void main(String[] args) {
// TODO 自动生成方法存根

}
 
 
private Client() throws HeadlessException {

// TODO 自动生成构造函数存根
//recordFrame = new JFrame();
//recordFrame = new JFrame();
//JFrame recordFrame = new JFrame();
ct.add(basePanel);
basePanel.setBorder(PublicClass.MARGIN);

setSize(606,520); 
//setAlwaysOnTop(true);
Toolkit  k = Toolkit.getDefaultToolkit();
Dimension screenArea = k.getScreenSize();
int x = (int)(screenArea.getWidth()- getWidth())/2;
setLocation(x,30);
recordFrame.setSize(606,100);
recordFrame.setLocation(x, 550);
recordFrame.setVisible(false);
//recordFrame.setResizable(false);
//recordFrame.setUndecorated(true);
//recordFrame.setFocusable(false);
//ct.add(recordFrame,BorderLayout.SOUTH);
recordFrame.getContentPane().add(bottomPane);
recordFrame.setUndecorated(true); // 去掉窗口的装饰
//getGlassPane().add(recordFrame);
// 采用指定的窗口装饰风格
 
//recordFrame.getRootPane().setWindowDecorationStyle(JRootPane.INFORMATION_DIALOG);    
bottomPane.setViewportView(recordPane);
Dimension d =new Dimension(590,100);
recordPane.setPreferredSize(d);
 
addComponentListener(new ComponentListener(){

public void componentResized(ComponentEvent arg0) {

// TODO 自动生成方法存根

recordFrame.setSize(getWidth(),100);
recordFrame.repaint();

}
 
public void componentMoved(ComponentEvent arg0) {
// TODO 自动生成方法存根
recordFrame.setLocation(getLocation().x,getLocation().y+getHeight());

}
 
public void componentShown(ComponentEvent arg0) {
// TODO 自动生成方法存根

}
 
public void componentHidden(ComponentEvent arg0) {
// TODO 自动生成方法存根

}

});
basePanel.add(headPanel,BorderLayout.NORTH);
//headPanel.add(portraitLabel,BorderLayout.WEST);



//basePanel.add(bottomPanel,BorderLayout.SOUTH);
//recordPane.setLocation(0,100);


//recordPane.setPreferredSize(d);

basePanel.add(centrePanel);
centrePanel.setBackground(Color.BLUE);
centrePanel.add(recordBtn);

recordBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
//Point g = new Point();
int y =0;
if(status)
{
//setSize(606,520);
status=false;
}
else
{
//setSize(606,620);
status=true;
}

recordFrame.setVisible(status);

//pack();
//PublicClass.toCentre(Logon.this);
}

});

addWindowListener(new WindowAdapter(){
 
public void windowClosing(WindowEvent arg0) {
// TODO 自动生成方法存根
recordFrame.dispose();
}
 
public void windowIconified(WindowEvent arg0) {
// TODO 自动生成方法存根
//recordFrame.setExtendedState(getExtendedState());
if(status)
recordFrame.setVisible(false);
}
 
public void windowDeiconified(WindowEvent arg0) {
// TODO 自动生成方法存根
if(status)
recordFrame.setVisible(true);
}

});

// recordFrame.addWindowListener(new WindowAdapter(){
//
// public void windowClosing(WindowEvent arg0) {
// // TODO 自动生成方法存根
// recordFrame.dispose();
// }
//
// public void windowIconified(WindowEvent arg0) {
// // TODO 自动生成方法存根
// recordFrame.setExtendedState(getExtendedState());
// //WindowAdapter.windowDeiconified(arg0);
// }
//
// public void windowDeiconified(WindowEvent arg0) {
// // TODO 自动生成方法存根
// recordFrame.setExtendedState(getExtendedState());
// }
//
// });


setVisible(true);



}

 
public static Client getClient()
{
return client;
}

 
} 以上代码,单击窗体上的按钮就会显示另一个窗体。 
现在我想用单个进程来控制这两个JFrame。 
但怎么改代码,都是由两个进程分别控制两个JFrame。 
(我要实现的功能有点像qq的聊天界面上的显示聊天记录。点击聊天记录按钮,就会跳出一个JFrame来,我看qq就是用一个进程来控制的,但我不知道它是怎么实现的) 

解决方案 »

  1.   

    package com.geostar.client.geosurfEditor;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class J_SelfLayout extends JFrame {
        public static void main(String args[]) {
            J_SelfLayout app = new J_SelfLayout();
            app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    }    public J_SelfLayout() {
            super("DiagonalLayout Example");
            Container cp = getContentPane();
            J_DiagonalLayout t = new J_DiagonalLayout();
            cp.setLayout(t);        for (int i = 0; i < 5; i++) {
                String s = "Button" + (i + 1);
                JButton b = new JButton(s);
                cp.add(b);
            }
            setSize(320, 200);
            setVisible(true);
        }
    }
      

  2.   

    请问老兄,J_DiagonalLayout这个类在哪