帮忙找一下错误,谢谢!

xmlh 2003-05-10 03:41:40
我想做一个类似qq的界面,在开始时我只是先做组的上下变化,这个我已经做好了
但是我在组里面添加新的按钮是,程序就不能正确的运行,我调了好几天,就是不知道错误在那里,只好麻烦各位大侠帮我看看了。谢谢!
...全文
29 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmlh 2003-05-12
  • 打赏
  • 举报
回复
谢谢,搞定了给分!
xmlh 2003-05-12
  • 打赏
  • 举报
回复
谢谢,搞定了给分!
xmlh 2003-05-11
  • 打赏
  • 举报
回复
好的我试看看,谢谢!
madisonklim 2003-05-11
  • 打赏
  • 举报
回复
把layout改成null就可以了!
xmlh 2003-05-10
  • 打赏
  • 举报
回复
void jButton3_actionPerformed(ActionEvent e) {
if(!show3){
if(up3){//panel3在上面并且没有显示,则缩小panel7~panel4的大小和位置,并把panel4下推
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jPanel3.getHeight()-jButton4.getHeight()-jPanel5.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
}
else{//panel3在下面,则扩大panel2和panel3的大小,然后下推panel4
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jPanel3.getHeight() -jPanel4.getHeight() ,150,jPanel4.getHeight() );
show3=true;show1=false;show2=false;
up2=true;up3=true;
}
}
}
void jButton4_actionPerformed(ActionEvent e) {
if(!show4){
if(!up4){//panel4在下面,这时可能panel1、panel2、panel3显示,只要把panel2、panel3和panel4扩大,并修改panel5 的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
// int temp=jPanel5.getHeight() ;
//jLabel1.setText(Integer.toString(jPanel3.getHeight() -jButton3.getHeight()));
jPanel5.setBounds(0,jPanel4.getHeight() -jPanel5.getHeight(),150,jPanel5.getHeight());
show4=true;show1=false;show2=false;show3=false;
up4=true;up2=true;up3=true;
}
else{//panel4在上面,这依次把panel7~panel5缩小并改变起点,然后把panel5下推
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jPanel4.getHeight() -jPanel6.getHeight() -jButton5.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
show4=true;show5=false;show6=false;show7=false;
up5=false;up6=false;up7=false;
}
}
}

void jButton5_actionPerformed(ActionEvent e) {
if (!show5){
if(!up5){//panel5在下面,则依次改变panel2~panel5的长度和位置,然后改变panel6的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jPanel5.getHeight() -jPanel6.getHeight() ,150,jPanel6.getHeight() );
show1=false;show2=false;show3=false;show4=false;
show5=true;up5=true;up2=true;up3=true;up4=true;
}
else{//panel5在上面,并且没有显示,这时说明要么panel6显示,要么panel7显示,则把panel7先缩小,在把panel6缩小,然后调整panel6的起点
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jPanel5.getHeight() -jButton6.getHeight() -jPanel7.getHeight() ,150,jButton6.getHeight() +jPanel6.getHeight() );
show5=true;
show6=false;show7=false;
up6=false;up7=false;
}

}
}

void jButton6_actionPerformed(ActionEvent e) {
if (!show6){
if(!up6){//panel6在下面,则依次改变panel2~panel6的长度和位置,然后改变panel7的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jPanel5.getHeight() -jButton5.getHeight() );
jPanel7.setBounds(0,jPanel6.getHeight() -jPanel7.getHeight() ,150,jPanel7.getHeight() );
show1=false;show2=false;show3=false;show4=false;show5=false;
show6=true;up5=true;up2=true;up3=true;up4=true;up6=true;
}
else{//panel6在上面,并且没有显示,这时说明panel7显示,则调整panel7的起点和大小
jPanel7.setBounds(0,jPanel6.getHeight() -jButton7.getHeight() ,150,20);
show6=true;
show7=false;
up7=false;
}

}
}

void jButton7_actionPerformed(ActionEvent e) {
if(!show7){//panel7没有被显示,说明panel7在下面,则依次扩大panel2~panel7的大小
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jPanel5.getHeight() -jButton5.getHeight() );
jPanel7.setBounds(0,jButton6.getHeight() ,150,jPanel6.getHeight() -jButton6.getHeight() );
show1=false;show2=false;show3=false;show4=false;show5=false;
show6=false;show7=false;
up7=true;up2=true;up3=true;up4=true;up5=true;up6=true;


}

}
xmlh 2003-05-10
  • 打赏
  • 举报
回复


jButton10.setVisible(true); jButton11.setVisible(true);
jButton12.setVisible(false); jButton13.setVisible(false);
jButton14.setVisible(false); jButton15.setVisible(false);
jButton16.setVisible(false); jButton17.setVisible(false);
jButton18.setVisible(false); jButton19.setVisible(false);
jButton20.setVisible(false); jButton21.setVisible(false);
jButton22.setVisible(false); jButton23.setVisible(false);


jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(xYLayout1);
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jPanel2.setLayout(xYLayout2);
jButton2.setText("jButton2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jPanel3.setLayout(xYLayout3);
jButton3.setText("jButton3");
jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
jPanel4.setLayout(xYLayout4);
jButton4.setText("jButton4");
jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));

contentPane.add(jPanel1, BorderLayout.WEST);
jPanel1.add(jButton1, new XYConstraints(0, 0,150, 20));
jPanel1.add(jPanel2, new XYConstraints(0, 230, 150, 120));

jPanel2.add(jButton2, new XYConstraints(0, 0,150, 20));
jPanel2.add(jPanel3, new XYConstraints(0, 20, 150, 100));
jPanel3.add(jButton3, new XYConstraints(0, 0, 150, 20));
jPanel3.add(jButton14, new XYConstraints(10,25,30,30));
jPanel3.add(jButton15, new XYConstraints(10,60,30,30));
jPanel3.add(jPanel4, new XYConstraints(0,20, 150, 80));

jPanel4.add(jButton4, new XYConstraints(0, 0,150, 20));
jPanel4.add(jButton16, new XYConstraints(10,25,30,30));
jPanel4.add(jButton17, new XYConstraints(10,60,30,30));
jPanel4.add(jPanel5, new XYConstraints(0, 20, 150, 60));
jPanel5.add(jButton5, new XYConstraints(0, 0,150, 20));
jPanel5.add(jButton18, new XYConstraints(10,25,30,30));
jPanel5.add(jButton19, new XYConstraints(10,60,30,30));
jPanel5.add(jPanel6, new XYConstraints(0,20, 150, 40));
jPanel6.add(jButton6, new XYConstraints(0, 0,150, 20));
jPanel6.add(jButton20, new XYConstraints(10,25,30,30));
jPanel6.add(jButton21, new XYConstraints(10, 60,30,30));
jPanel6.add(jPanel7, new XYConstraints(0, 20, 150, 20));
jPanel7.add(jButton7, new XYConstraints(0, 0,150, 20));
jPanel7.add(jButton23, new XYConstraints(10,25,30,30));
jPanel7.add(jButton22, new XYConstraints(10, 60,30,30));

jPanel1.add(jButton10, new XYConstraints(10, 25, 30, 30));
jPanel1.add(jButton11, new XYConstraints(10, 60, 30, 30));

jPanel2.add(jButton12, new XYConstraints(10,25,30,30));
jPanel2.add(jButton13, new XYConstraints(10,60,30,30));



contentPane.add(jPanel8, BorderLayout.CENTER);
jPanel8.add(jLabel1, new XYConstraints(34, 55, 147, 35));
jPanel8.add(jLabel2, new XYConstraints(33, 119, 148, 36));
System.out.println(jButton12.getY() );
System.out.println(jButton12.getX() );
System.out.println(jButton12.getHeight() );


}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jButton1_actionPerformed(ActionEvent e) {

if (!show1){//依次改变panel7~panel2的大小,并且把panel2下推

jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
jPanel3.setBounds(0,jButton2.getHeight() ,150,jButton3.getHeight() +jPanel4.getHeight() );
jPanel2.setBounds(0,jPanel1.getHeight() - jButton2.getHeight() - jPanel3.getHeight() ,150,jButton2.getHeight() +jPanel3.getHeight() );
show1=true;show2=false;show3=false;show4=false;show5=false;
show6=false;show7=false;
up2=false;up3=false;up4=false;up5=false;up6=false;up7=false;
jButton10.setVisible(true); jButton11.setVisible(true);
jButton12.setVisible(false); jButton13.setVisible(false);
jButton14.setVisible(false); jButton15.setVisible(false);
jButton16.setVisible(false); jButton17.setVisible(false);
jButton18.setVisible(false); jButton19.setVisible(false);
jButton20.setVisible(false); jButton21.setVisible(false);
jButton22.setVisible(false); jButton23.setVisible(false);
}
void jButton2_actionPerformed(ActionEvent e) {
jButton12.setBounds(10,25,30,30);jButton13.setBounds(10,60,30,30);


if(!show2){

if(up2){//依次缩小panel7~panel3的大小并改变他们的起点
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
jPanel3.setBounds(0,jPanel2.getHeight() -jPanel4.getHeight()-jButton3.getHeight() ,150,jButton3.getHeight() +jPanel4.getHeight() );
show2=true;show3=false;show4=false;show5=false;show6=false;
show7=false;up3=false;up4=false;up5=false;up6=false;up7=false;
}
else{//panel2在下面,则改变panel2的大小和起点,在改变panel3的起点
// jButton12.setVisible(true);jButton13.setVisible(true);
// jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
//jPanel2.setSize(150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jPanel2.getHeight() -jPanel3.getHeight() ,150,jPanel3.getHeight() );

up2=true;show2=true;show1=false;
System.out.println(jButton1.getHeight() );
}

jButton10.setVisible(false); jButton11.setVisible(false);
jButton12.setVisible(true); jButton13.setVisible(true);
jButton14.setVisible(false); jButton15.setVisible(false);
jButton16.setVisible(false); jButton17.setVisible(false);
jButton18.setVisible(false); jButton19.setVisible(false);
jButton20.setVisible(false); jButton21.setVisible(false);
jButton22.setVisible(false); jButton23.setVisible(false);
System.out.println(jPanel2.getY() );
System.out.println(jPanel2.getHeight());
System.out.println(jButton12.getY() );
System.out.println(jButton12.getX() );
System.out.println(jButton12.getHeight() );

}
}
xmlh 2003-05-10
  • 打赏
  • 举报
回复
这个是我在组添加按钮后的程序:
package gcss1;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;


/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class MainFrame extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton8 = new JButton();
JButton jButton9 = new JButton();

ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();


private boolean show1=true;
private boolean up2,show2,up3,show3,up4,show4,
up5,show5,up6,show6,up7,show7=false;
private boolean change=true;



JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel2 = new JPanel();
JButton jButton2 = new JButton();
XYLayout xYLayout2 = new XYLayout();
JPanel jPanel3 = new JPanel();
XYLayout xYLayout3 = new XYLayout();
JButton jButton3 = new JButton();
JPanel jPanel4 = new JPanel();
XYLayout xYLayout4 = new XYLayout();
JButton jButton4 = new JButton();
XYLayout xYLayout8 = new XYLayout();
JPanel jPanel8 = new JPanel();


JLabel jLabel1 = new JLabel();
XYLayout xYLayout9 = new XYLayout();
JLabel jLabel2 = new JLabel();
JButton jButton10 = new JButton();
JButton jButton11 = new JButton();
JButton jButton12 = new JButton();
JButton jButton13 = new JButton();
JButton jButton14 = new JButton();
JButton jButton15 = new JButton();
JButton jButton16 = new JButton();
JButton jButton17 = new JButton();
JButton jButton5 = new JButton();
JPanel jPanel5 = new JPanel();
XYLayout xYLayout5 = new XYLayout();
JButton jButton18 = new JButton();
JButton jButton19 = new JButton();
JButton jButton6 = new JButton();
JPanel jPanel6 = new JPanel();
XYLayout xYLayout6 = new XYLayout();
JButton jButton20 = new JButton();
JButton jButton21 = new JButton();
JButton jButton22 = new JButton();
JButton jButton7 = new JButton();
JPanel jPanel7 = new JPanel();
JButton jButton23 = new JButton();
XYLayout xYLayout7 = new XYLayout();
BorderLayout borderLayout1 = new BorderLayout();


//Construct the frame
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
if(change){
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
change=false;
}
//Component initialization
private void jbInit() throws Exception {
image1 = new ImageIcon(gcss1.MainFrame.class.getResource("openFile.png"));
image2 = new ImageIcon(gcss1.MainFrame.class.getResource("closeFile.png"));
image3 = new ImageIcon(gcss1.MainFrame.class.getResource("help.png"));


contentPane = (JPanel) this.getContentPane();
contentPane.setBorder(BorderFactory.createEtchedBorder());
//contentPane.addComponentListener(new MainFrame_contentPane_componentAdapter(this));
contentPane.setLayout(borderLayout1);



this.setSize(new Dimension(600,450));
this.setTitle("Frame Title");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new MainFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new MainFrame_jMenuHelpAbout_ActionAdapter(this));
jButton8.setIcon(image1);
jButton8.setToolTipText("Open File");
jButton9.setIcon(image2);
jButton9.setToolTipText("Close File");
jButton3.setToolTipText("Help");
contentPane.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(xYLayout8);
jPanel8.setBorder(BorderFactory.createEtchedBorder());
jPanel8.setLayout(xYLayout9);
jPanel8.addComponentListener(new MainFrame_jPanel8_componentAdapter(this));
jPanel1.setBackground(new Color(233, 244, 255));
jPanel2.setBorder(null);
jPanel3.setBorder(null);
jPanel4.setBorder(null);
jLabel1.setText("jLabel1");
jLabel2.setText("jLabel2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jButton10.setText("jButton10");
jButton11.setText("jButton11");
jButton12.setText("jButton12");
jButton13.setText("jButton13");
jButton14.setText("jButton14");
jButton15.setText("jButton15");
jButton16.setText("jButton16");
jButton17.setText("jButton17");
jButton5.setText("jButton5");
jButton5.addActionListener(new Frame1_jButton5_actionAdapter(this));
jPanel5.setBorder(null);
jPanel5.setLayout(xYLayout5);
jButton18.setText("jButton18");
jButton19.setText("jButton19");
jButton6.setText("jButton6");
jButton6.addActionListener(new Frame1_jButton6_actionAdapter(this));
jPanel6.setBorder(null);
jPanel6.setLayout(xYLayout6);
jButton20.setText("jButton20");
jButton21.setText("jButton21");
jButton22.setText("jButton21");
jButton7.addActionListener(new Frame1_jButton7_actionAdapter(this));
jButton7.setText("jButton6");
jPanel7.setLayout(xYLayout7);
jPanel7.setBorder(null);
jButton23.setText("jButton20");
jToolBar.add(jButton8);
jToolBar.add(jButton9);
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
wawawawa 2003-05-10
  • 打赏
  • 举报
回复
太长了吧,不如把错误信息贴出来,自己通过打印或者单步来定位,将错误部分代码贴出来更好
xmlh 2003-05-10
  • 打赏
  • 举报
回复
void contentPane_componentResized(ComponentEvent e) {
/* if (up2){//panel2在上面,当窗口变化时要改变panel2的长度
if(up3){//panel3也在上面,先改变panel2的长度,在改变panel3的大小
jPanel2.setBounds(-2,jButton1.getHeight() ,80,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(-2,jButton3.getHeight() ,80,jPanel2.getHeight() -jButton2.getHeight() );
}
else{//panel3在下面,则先改变panel2的长度,在改变panel3的起点
jPanel2.setBounds(-2,jButton1.getHeight() ,80,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(-2,jPanel2.getHeight() -jButton3.getHeight() ,80,jButton3.getHeight() );
}
}else{//panel2在下面,只要给变panel2的起点就可以了
jPanel2.setBounds(-2,jPanel1.getHeight() -jPanel2.getHeight() ,80,jPanel2.getHeight() );

}*/

}

void jPanel8_componentResized(ComponentEvent e) {
if(!up2){//panel2不在上面,只要改变一下panel2的起点位置就可以了
jPanel2.setBounds(0,jPanel1.getHeight() -jPanel2.getHeight() ,150,jPanel2.getHeight());
}
else{//先改变panel2的长度,在判断panel3的情况
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
if(!up3){//panel3不在上面,只要改变一下panel3的起点位置就可以了
jPanel3.setBounds(0,jPanel2.getHeight()-jPanel3.getHeight(),150,jPanel3.getHeight());
}
else{//先改变panel3的长度,在判断panel4的情况
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
if(!up4){//panel4不在上面,只要改变一下panel4的起点位置就可以了
jPanel4.setBounds(0,jPanel3.getHeight()-jPanel4.getHeight(),150,jPanel4.getHeight());
}
else{//先改变panel4的长度,在判断panel5的情况
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
if(!up5){//panel5不在上面,只要改变一下panel5的起点位置就可以了
jPanel5.setBounds(0,jPanel4.getHeight()-jPanel5.getHeight(),150,jPanel5.getHeight());
}
else{//先改变panel5的长度,在判断panel6的情况
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
if(!up6){//panel6不在上面,只要改变一下panel6的起点位置就可以了
jPanel6.setBounds(0,jPanel5.getHeight() -jPanel6.getHeight() ,150,jPanel6.getHeight() );
}
else { //先改变panel6的长度,在判断panel7的情况
jPanel6.setBounds(0,jButton5.getHeight() ,150,jPanel5.getHeight() -jButton5.getHeight() );
if(!up7){//panel7不在上面,只要改变一下panel7的起点位置就可以了
jPanel7.setBounds(0,jPanel6.getHeight() -jButton7.getHeight() ,150,jPanel7.getHeight() );
}
else{//改变panel7的长度
jPanel7.setBounds(0,jButton6.getHeight() ,150,jPanel6.getHeight() -jButton6.getHeight() );

}
}

}
}


}

}
}

class MainFrame_jMenuFileExit_ActionAdapter implements ActionListener {
MainFrame adaptee;

MainFrame_jMenuFileExit_ActionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileExit_actionPerformed(e);
}
}

class MainFrame_jMenuHelpAbout_ActionAdapter implements ActionListener {
MainFrame adaptee;

MainFrame_jMenuHelpAbout_ActionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}
class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton2_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}

class Frame1_jButton3_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton3_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}



class Frame1_jButton4_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton4_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}

class Frame1_jButton5_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton5_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}

class Frame1_jButton6_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton6_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton6_actionPerformed(e);
}
}

class Frame1_jButton7_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton7_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton7_actionPerformed(e);
}
}

class MainFrame_jPanel8_componentAdapter extends java.awt.event.ComponentAdapter {
MainFrame adaptee;

MainFrame_jPanel8_componentAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void componentResized(ComponentEvent e) {
adaptee.jPanel8_componentResized(e);
}
}
}

class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
MainFrame adaptee;

Frame1_jButton2_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

xmlh 2003-05-10
  • 打赏
  • 举报
回复
void jButton1_actionPerformed(ActionEvent e) {

if (!show1){//依次改变panel7~panel2的大小,并且把panel2下推

jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
jPanel3.setBounds(0,jButton2.getHeight() ,150,jButton3.getHeight() +jPanel4.getHeight() );
jPanel2.setBounds(0,jPanel1.getHeight() - jButton2.getHeight() - jPanel3.getHeight() ,150,jButton2.getHeight() +jPanel3.getHeight() );
show1=true;show2=false;show3=false;show4=false;show5=false;
show6=false;show7=false;
up2=false;up3=false;up4=false;up5=false;up6=false;up7=false;

}
}

void jButton2_actionPerformed(ActionEvent e) {
if(!show2){
if(up2){//依次缩小panel7~panel3的大小并改变他们的起点
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
jPanel3.setBounds(0,jPanel2.getHeight() -jPanel4.getHeight()-jButton3.getHeight() ,150,jButton3.getHeight() +jPanel4.getHeight() );
show2=true;show3=false;show4=false;show5=false;show6=false;
show7=false;up3=false;up4=false;up5=false;up6=false;up7=false;
}
else{//panel2在下面,则改变panel2的大小和起点,在改变panel3的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jPanel2.getHeight() -jPanel3.getHeight() ,150,jPanel3.getHeight() );
up2=true;show2=true;show1=false;
}
}

}

void jButton3_actionPerformed(ActionEvent e) {
if(!show3){
if(up3){//panel3在上面并且没有显示,则缩小panel7~panel4的大小和位置,并把panel4下推
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
jPanel4.setBounds(0,jPanel3.getHeight()-jButton4.getHeight()-jPanel5.getHeight() ,150,jButton4.getHeight() +jPanel5.getHeight());
}
else{//panel3在下面,则扩大panel2和panel3的大小,然后下推panel4
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jPanel3.getHeight() -jPanel4.getHeight() ,150,jPanel4.getHeight() );
show3=true;show1=false;show2=false;
up2=true;up3=true;
}
}
}

void jButton4_actionPerformed(ActionEvent e) {
if(!show4){
if(!up4){//panel4在下面,这时可能panel1、panel2、panel3显示,只要把panel2、panel3和panel4扩大,并修改panel5 的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jPanel4.getHeight() -jPanel5.getHeight(),150,jPanel5.getHeight());
show4=true;show1=false;show2=false;show3=false;
up4=true;up2=true;up3=true;
}
else{//panel4在上面,这依次把panel7~panel5缩小并改变起点,然后把panel5下推
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jButton6.getHeight() +jPanel7.getHeight() );
jPanel5.setBounds(0,jPanel4.getHeight() -jPanel6.getHeight() -jButton5.getHeight() ,150,jButton5.getHeight() +jPanel6.getHeight() );
show4=true;show5=false;show6=false;show7=false;
up5=false;up6=false;up7=false;
}
}
}
void jButton5_actionPerformed(ActionEvent e) {
if (!show5){
if(!up5){//panel5在下面,则依次改变panel2~panel5的长度和位置,然后改变panel6的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jPanel5.getHeight() -jPanel6.getHeight() ,150,jPanel6.getHeight() );
show1=false;show2=false;show3=false;show4=false;
show5=true;up5=true;up2=true;up3=true;up4=true;
}
else{//panel5在上面,并且没有显示,这时说明要么panel6显示,要么panel7显示,则把panel7先缩小,在把panel6缩小,然后调整panel6的起点
jPanel7.setBounds(0,jButton6.getHeight() ,150,jButton7.getHeight() );
jPanel6.setBounds(0,jPanel5.getHeight() -jButton6.getHeight() -jPanel7.getHeight() ,150,jButton6.getHeight() +jPanel6.getHeight() );
show5=true;
show6=false;show7=false;
up6=false;up7=false;
}
}
}
void jButton6_actionPerformed(ActionEvent e) {
if (!show6){
if(!up6){//panel6在下面,则依次改变panel2~panel6的长度和位置,然后改变panel7的起点
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jPanel5.getHeight() -jButton5.getHeight() );
jPanel7.setBounds(0,jPanel6.getHeight() -jPanel7.getHeight() ,150,jPanel7.getHeight() );
show1=false;show2=false;show3=false;show4=false;show5=false;
show6=true;up5=true;up2=true;up3=true;up4=true;up6=true;
}
else{//panel6在上面,并且没有显示,这时说明panel7显示,则调整panel7的起点和大小
jPanel7.setBounds(0,jPanel6.getHeight() -jButton7.getHeight() ,150,20);
show6=true; show7=false; up7=false;
}
}
}

void jButton7_actionPerformed(ActionEvent e) {
if(!show7){//panel7没有被显示,说明panel7在下面,则依次扩大panel2~panel7的大小
jPanel2.setBounds(0,jButton1.getHeight() ,150,jPanel1.getHeight() -jButton1.getHeight() );
jPanel3.setBounds(0,jButton2.getHeight() ,150,jPanel2.getHeight() -jButton2.getHeight() );
jPanel4.setBounds(0,jButton3.getHeight() ,150,jPanel3.getHeight() -jButton3.getHeight() );
jPanel5.setBounds(0,jButton4.getHeight() ,150,jPanel4.getHeight() -jButton4.getHeight() );
jPanel6.setBounds(0,jButton5.getHeight() ,150,jPanel5.getHeight() -jButton5.getHeight() );
jPanel7.setBounds(0,jButton6.getHeight() ,150,jPanel6.getHeight() -jButton6.getHeight() );
show1=false;show2=false;show3=false;show4=false;show5=false;
show6=false;show7=false;
up7=true;up2=true;up3=true;up4=true;up5=true;up6=true;
}

}
xmlh 2003-05-10
  • 打赏
  • 举报
回复
这个是我的源程序:(还没有往组添加按钮)
package gcss1;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;


/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class MainFrame extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton8 = new JButton();
JButton jButton9 = new JButton();

ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();


private boolean show1=true;
private boolean up2,show2,up3,show3,up4,show4,
up5,show5,up6,show6,up7,show7=false;
private boolean change=true;
//show用于判断panel是否被显示,up用于判断panel是否在上面

JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel2 = new JPanel();
JButton jButton2 = new JButton();
XYLayout xYLayout2 = new XYLayout();
JPanel jPanel3 = new JPanel();
XYLayout xYLayout3 = new XYLayout();
JButton jButton3 = new JButton();
JPanel jPanel4 = new JPanel();
XYLayout xYLayout4 = new XYLayout();
JButton jButton4 = new JButton();
JPanel jPanel5 = new JPanel();
XYLayout xYLayout5 = new XYLayout();
JButton jButton5 = new JButton();
JPanel jPanel6 = new JPanel();
XYLayout xYLayout6 = new XYLayout();
JButton jButton6 = new JButton();
JPanel jPanel7 = new JPanel();
XYLayout xYLayout7 = new XYLayout();
JButton jButton7 = new JButton();
XYLayout xYLayout8 = new XYLayout();
JPanel jPanel8 = new JPanel();


JLabel jLabel1 = new JLabel();
XYLayout xYLayout9 = new XYLayout();
JLabel jLabel2 = new JLabel();
JButton jButton10 = new JButton();
JButton jButton11 = new JButton();


//Construct the frame
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
if(change){
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
change=false;
}
//Component initialization
private void jbInit() throws Exception {
image1 = new ImageIcon(gcss1.MainFrame.class.getResource("openFile.png"));
image2 = new ImageIcon(gcss1.MainFrame.class.getResource("closeFile.png"));
image3 = new ImageIcon(gcss1.MainFrame.class.getResource("help.png"));


contentPane = (JPanel) this.getContentPane();
contentPane.setBorder(BorderFactory.createEtchedBorder());
//contentPane.addComponentListener(new MainFrame_contentPane_componentAdapter(this));
contentPane.setLayout(borderLayout1);



this.setSize(new Dimension(600,450));
this.setTitle("Frame Title");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new MainFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new MainFrame_jMenuHelpAbout_ActionAdapter(this));
jButton8.setIcon(image1);
jButton8.setToolTipText("Open File");
jButton9.setIcon(image2);
jButton9.setToolTipText("Close File");
jButton3.setToolTipText("Help");
contentPane.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(xYLayout8);
jPanel8.setBorder(BorderFactory.createEtchedBorder());
jPanel8.setLayout(xYLayout9);
jPanel8.addComponentListener(new MainFrame_jPanel8_componentAdapter(this));
jPanel1.setBackground(new Color(233, 244, 255));
jPanel2.setBorder(null);
jPanel3.setBorder(null);
jPanel4.setBorder(null);
jPanel5.setBorder(null);
jPanel6.setBorder(null);
jLabel1.setText("jLabel1");
jLabel2.setText("jLabel2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jButton10.setText("jButton10");
jButton11.setText("jButton11");
jToolBar.add(jButton8);
jToolBar.add(jButton9);
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);


jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(xYLayout1);
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jPanel2.setLayout(xYLayout2);
jButton2.setText("jButton2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jPanel3.setLayout(xYLayout3);
jButton3.setText("jButton3");
jButton3.addActionListener(new Frame1_jButton3_actionAdapter(this));
jPanel4.setLayout(xYLayout4);
jButton4.setText("jButton4");
jButton4.addActionListener(new Frame1_jButton4_actionAdapter(this));
jPanel5.setLayout(xYLayout5);
jButton5.setText("jButton5");
jButton5.addActionListener(new Frame1_jButton5_actionAdapter(this));
jPanel6.setLayout(xYLayout6);
jButton6.setText("jButton6");
jButton6.addActionListener(new Frame1_jButton6_actionAdapter(this));
jPanel7.setLayout(xYLayout7);
jButton7.setText("jButton7");
jButton7.addActionListener(new Frame1_jButton7_actionAdapter(this));

contentPane.add(jPanel1, BorderLayout.WEST);
jPanel1.add(jButton1, new XYConstraints(0, 0,150, 20));

jPanel1.add(jPanel2, new XYConstraints(0, 230, 150, 120));

jPanel2.add(jButton2, new XYConstraints(0, 0,150, 20));
jPanel2.add(jPanel3, new XYConstraints(0, 20, 150, 100));

jPanel3.add(jButton3, new XYConstraints(0, 0, 150, 20));
jPanel3.add(jPanel4, new XYConstraints(0,20, 150, 80));

jPanel4.add(jButton4, new XYConstraints(0, 0,150, 20));
jPanel4.add(jPanel5, new XYConstraints(0, 20, 150, 60));

jPanel5.add(jButton5, new XYConstraints(0, 0,150, 20));
jPanel5.add(jPanel6, new XYConstraints(0,20, 150, 40));

jPanel6.add(jButton6, new XYConstraints(0, 0,150, 20));
jPanel6.add(jPanel7, new XYConstraints(0, 20, 150, 20));

jPanel7.add(jButton7, new XYConstraints(0, 0,150, 20));
jPanel1.add(jButton10, new XYConstraints(14, 31, -1, -1));
jPanel1.add(jButton11, new XYConstraints(17, 62, 85, 26));


contentPane.add(jPanel8, BorderLayout.CENTER);
jPanel8.add(jLabel1, new XYConstraints(34, 55, 147, 35));
jPanel8.add(jLabel2, new XYConstraints(33, 119, 148, 36));


}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧