Fehlerhafte Graphikausgabe beim Switchen zwischen 2 verschiedenen Programm-Modi.
Ich habe auch versucht nach dem Switch mit 'repaint' oder 'update' etwas zu erreichen, aber ohne Erfolg
Grüße aus Sachsen und Danke schon mal für die Hilfe!
Ich habe auch versucht nach dem Switch mit 'repaint' oder 'update' etwas zu erreichen, aber ohne Erfolg
Java:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created with IntelliJ IDEA.
* User: wonderer
* Date: 19.08.12
* Time: 11:31
* To change this template use File | Settings | File Templates.
*/
public class MainForm extends Frame {
private Button btSwitchToFunc1;
private Button btSwitchToFunc2;
private Dimension func1Dimension;
private Dimension func2Dimension;
private Dimension scrSize;
private Panel mainPanel;
private Panel centerPanel;
private Panel southPanel;
public MainForm(){
initFrame();
this.setVisible(true);
}
public void initFrame(){
// set vars
scrSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
func2Dimension = new Dimension(500,750);
func1Dimension = new Dimension(350,350);
// init frame
this.setSize(libDimension);
this.setLocation(new Point(scrSize.width/2-func2Dimension.width/2,scrSize.height/2-func2Dimension.height/2));
// init components
btSwitchToFunc1 = new Button("switch to 1");
btSwitchToFunc2 = new Button("switch to 2");
btSwitchToFunc1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Button btSwitch = (Button)actionEvent.getSource();
MainForm parentFrame = (MainForm)btSwitch.getParent().getParent();
parentFrame.switchFunction(btSwitch);
}
});
btSwitchToFunc2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Button btSwitch = (Button)actionEvent.getSource();
MainForm parentFrame = (MainForm)btSwitch.getParent().getParent();
parentFrame.switchFunction(btSwitch);
}
});
selectSome = new Choice();
selectSome.addItem("1");
selectSome.addItem("3");
Label lblSelect = new Label("Label: ");
// add components
mainPanel = new Panel();
this.add(mainPanel);
mainPanel.setLayout(new BorderLayout());
mainPanel.add(btSwitchToFunc1, BorderLayout.NORTH);
centerPanel = new Panel();
centerPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
centerPanel.setSize(new Dimension(500,250));
Panel dumPan = new Panel();
dumPan.setLayout(new FlowLayout(FlowLayout.RIGHT));
dumPan.setPreferredSize(new Dimension(240, 42));
dumPan.add(lblSelect);
lblSelect.setPreferredSize(new Dimension(182, 42));
centerPanel.add(dumPan);
dumPan = new Panel();
dumPan.setLayout(new FlowLayout(FlowLayout.LEFT));
dumPan.setPreferredSize(new Dimension(240, 42));
int cntPanWidth = centerPanel.getSize().width;
selectSome.setPreferredSize(new Dimension(165, 42));
dumPan.add(selectSome);
centerPanel.add(dumPan);
mainPanel.add(centerPanel, BorderLayout.CENTER);
}
public void switchFunction(Button btActualFunction){
//System.out.println(northPanel.getComponentCount());
//Button btActualFunction = (Button)mainPanel.getComponent(0);
if( btActualFunction.getLabel().equals("switch to 1")) {
this.setSize(func1Dimension);
this.setLocation(scrSize.width-func1Dimension.width,this.getLocation().y);
mainPanel.remove(btSwitchToFunc1);
mainPanel.remove(centerPanel);
mainPanel.add(btSwitchToFunc2, BorderLayout.NORTH);
} else {
this.setSize(func2Dimension);
this.setLocation(new Point(scrSize.width / 2 - libDimension.width / 2, scrSize.height / 2 - libDimension.height / 2));
//btSwitchFunction.setLabel("switch to education");
mainPanel.remove(btSwitchToFunc2);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(btSwitchToFunc1, BorderLayout.NORTH);
}
this.repaint();
//btSwitch.repaint();
//paFrame.update(paFrame.getGraphics());
}
static class TestWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().dispose();
System.exit(0);
}
}
public static void main( String[] args ){
MainForm myForm = new MainForm();
myForm.addWindowListener(new TestWindowListener());
}
}
Grüße aus Sachsen und Danke schon mal für die Hilfe!