Ich hab mir hier ein kleines System geschrieben, das verschiedene GUI managen soll.
Das soll ermöglichen von überall ohne probleme auf die GUI Element drauf zu zugreifen.
Nun wird aber keines dieser Element angezeigt,
View.java
ViewContainer
Wenn ich dies nun so aufrufe wird nichts angezeigt und ich weiß einfach nicht warum ?!
Ich hoffe ihr könnt mir helfen. Bin echt ratlos!
Schon mal Danke im Vorraus.
Mfg
NecroniX
Das soll ermöglichen von überall ohne probleme auf die GUI Element drauf zu zugreifen.
Nun wird aber keines dieser Element angezeigt,
View.java
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Random;
import java.util.Hashtable;
import Core.Interfaces.Item;
import Core.Exceptions.*;
public class View {
long id;
String name;
JFrame mainFrame;
Hashtable<String,ViewContainer> container = new Hashtable();
Hashtable<String,String> _ = new Hashtable();
public View () {
this.mainFrame = new JFrame();
this.getMainFrame().setBounds(100, 100, 400, 400);
this.getMainFrame().setLayout(null);
this.getMainFrame().setVisible(true);
Random random = new Random();
this.id = random.nextLong();
}
public View (JFrame frame) {
this.mainFrame = frame;
}
public JFrame getMainFrame() {
return this.mainFrame;
}
public void setMainFrame(JFrame frame) {
this.mainFrame = frame;
}
public void addContainer(String name,ViewContainer container) {
this.container.put(name, container);
this.mainFrame.getContentPane().add(container.getContainer());
}
public ViewContainer getContainer(String containerName) {
return this.container.get(containerName);
}
public void showView() {
/*
JLabel label2 =(JLabel) this.getContainer("Programm").getComponent("label2");
System.out.println(label2.getText());
System.out.println(this.getContainer("Programm").getComponent("label2").toString());
*/ System.out.println("Test");
}
}
ViewContainer
Java:
import java.awt.Container;
import java.awt.Component;
import java.util.Hashtable;
import java.util.Set;
import java.util.Random;
public class ViewContainer {
String name;
long id;
Container container;
Hashtable<String,Component> components = new Hashtable();
Hashtable<String,String> _ = new Hashtable();
public ViewContainer(Container cp,String name) {
Random random = new Random();
this.container = cp;
this.id = random.nextLong();
this.name = name;
}
public ViewContainer(String name) {
Random random = new Random();
this.container = new Container();
this.id = random.nextLong();
this.name = name;
}
public void addComponent(String componentName,Component component) {
this.components.put(componentName, component);
this.container.add(component);
}
public Component getComponent(String componentName) {
return this.components.get(componentName);
}
public Set getAllComponents() {
return this.components.entrySet();
}
public Container getContainer() {
return this.container;
}
public void addValue(String name, String value) {
this._.put(name, value);
}
public String getValue(String name) {
return this._.get(name);
}
}
Wenn ich dies nun so aufrufe wird nichts angezeigt und ich weiß einfach nicht warum ?!
Java:
import java.awt.*;
import javax.swing.*;
/**
*
* @author GRADY
*/
public class MainClass {
public static void main(String args[]) {
View mainView = new View();
JLabel label2 = new JLabel("nix");
ViewContainer cp = new ViewContainer("content");
label2.setBounds(200, 100, 50,20);
cp.addComponent("label2",label2);
mainView.addContainer("Programm", cp );
mainView.showView();
}
}
Ich hoffe ihr könnt mir helfen. Bin echt ratlos!
Schon mal Danke im Vorraus.
Mfg
NecroniX