Flyvske paneler
Halløjsa!Jeg har lavet et lille program i Borland Builder 8.0, hvor jeg kan flytte rundt på et panel, og skjule det.
Man kan flytte panelet ved at trække i det.
Problemet er at paneler ryger tilbage til sin orriginale pladsering, når det bliver skjult/vist...
Nogen der kan forklare hvorfor? Er det pga. XY-layoutet? (Som er med i Buildere).
Hvad kan man gøre for at fixe det?
Tak!
----
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Applet1 extends Applet {
private boolean isStandalone = false;
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
boolean vis=true;
JButton jButton1 = new JButton();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
jPanel1.setBackground(Color.red);
jPanel1.addMouseMotionListener(new Applet1_jPanel1_mouseMotionAdapter(this));
jButton1.setText("jButton1");
jButton1.addActionListener(new Applet1_jButton1_actionAdapter(this));
this.add(jPanel1, new XYConstraints(153, 19, 84, 162));
this.add(jButton1, new XYConstraints(155, 198, 74, 71));
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void jButton1_actionPerformed(ActionEvent e) {
vis=!vis;
jPanel1.setVisible(vis);
}
void jPanel1_mouseDragged(MouseEvent e) {
jPanel1.setLocation(e.getX()+jPanel1.getX(), e.getY()+jPanel1.getY());
}
}
class Applet1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Applet1 adaptee;
Applet1_jButton1_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Applet1_jPanel1_mouseMotionAdapter extends java.awt.event.MouseMotionAdapter {
Applet1 adaptee;
Applet1_jPanel1_mouseMotionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void mouseDragged(MouseEvent e) {
adaptee.jPanel1_mouseDragged(e);
}
}