GDialog and GDetachedPanel

De GENIUS
Aller à la navigation Aller à la recherche

GENIUS proposes to display information in detached windows. Two objects may be used depending on the fact that the window has a modal comportment or not:

The principle is more or less the same for both classes: we have to create a class extending GDetachedPanel or GDialog (as extending GPanel):

public class GDetachedPanelWidget extends GDetachedPanel {
	
	private GLabel lab;
	
	public GDetachedPanelWidget( String title ) {
		super(title);
		lab = new GLabel("GDetachedPanel test ...");
		this.getJFrame().setPreferredSize(new Dimension(200, 100));
		this.getJFrame().setLocation(200, 0);
	}
	
	@Override
	public void display() throws GException {
		generic();
	}
	
	@Override
	public void generic() throws GException {
		put(lab);
	}

}
public class GDialogWidget extends GDialog {
	
	private GLabel lab;
	
	public GDialogWidget( String title ) {
		super(title);
		lab = new GLabel("GDialog test ...");
		this.getJPanel().setPreferredSize(new Dimension(180, 60));
	}
	
	@Override
	public void display() throws GException {
		generic();
	}
	
	@Override
	public void generic() throws GException {
		put(lab);
	}

}

Then, the difference will be on the way to call them to be displayed:

  • for GDetachedPanel, it will be as for a GPanel via the put() method.
  • for GDialog, we will have to call for the display() method of the object ; we will exit of this method when the GDialog window will have been closed.
public class TestForGDialogAndGDetachedPanel extends GPanel {
	
	private GCheckBox cbDialog;
	private GCheckBox cbDetach;

	private GDialogWidget dialog;
	private GDetachedPanelWidget detach;
	
	public TestForGDialogAndGDetachedPanel() {
		
		cbDetach = new GCheckBox("Test GDetachedPanel");
		cbDialog = new GCheckBox("Test GDialog");
		
		detach = new GDetachedPanelWidget("GDetachedPanel");
		dialog = new GDialogWidget("GDialog");

	}

	@Override
	public void display() throws GException {
		generic();
	}

	@Override
	public void generic() throws GException {
		put(cbDetach);
		if ( cbDetach.isSelected() ) {
			put(detach);
		}
		put(cbDialog);
		if ( cbDialog.isSelected() ) {
			dialog.show();
			cbDialog.setSelected(false);
		}
	}

}

Using the code above, we will have this:


GDetachedAndDialog1.jpg


by clicking on the checkbox for GDetachedPanel], a detached window will appear ...


GDetachedAndDialog2.jpg GDetachedPanel.jpg


... and by clicking on the checkbox for GDialog, the following window will appear when the main window will be deactivated:


GDialog.jpg


Return to the introduction ↑ Go to the next page →