I want t have some picture above another one and want to utilize PCamera's addLayer() method.
Is this possible?
The following code throws NullPointerException. What's wrong with it?
package test.piccolo;
import java.awt.Color;
import edu.umd.cs.piccolo.PCamera;
import edu.umd.cs.piccolo.PLayer;
import edu.umd.cs.piccolo.nodes.PPath;
import edu.umd.cs.piccolox.PFrame;
public class Try_Cameras_01 {
#SuppressWarnings("serial")
public static void main(String[] args) {
new PFrame() {
private PLayer layer1 = new PLayer();
private PLayer layer2 = new PLayer();
private PLayer layer3 = new PLayer();
private PCamera camera = new PCamera();
{
camera.addLayer(layer1);
camera.addLayer(layer2);
camera.addLayer(layer3);
}
#Override
public void initialize() {
getCanvas().setCamera(camera);
PPath redRectangle = PPath.createRectangle(0, 0, 100, 100);
redRectangle.setStrokePaint(Color.black);
redRectangle.setPaint(Color.red);
PPath greenRectangle = PPath.createRectangle(20, 20, 100, 100);
greenRectangle.setStrokePaint(Color.black);
greenRectangle.setPaint(Color.green);
PPath blueRectangle = PPath.createRectangle(40, 40, 100, 100);
blueRectangle.setStrokePaint(Color.black);
blueRectangle.setPaint(Color.blue);
layer1.addChild(redRectangle);
layer2.addChild(greenRectangle);
layer3.addChild(blueRectangle);
}
};
}
}
The problem is that when you set up a new camera it has no associated root. As a result, PCanvas.getRoot() returns null and there an NPE in one of the painting methods. Here is a basic Piccolo2D runtime structure:
Read more in Piccolo2D Patterns.
In your case you're missing a link to PRoot from a PCamera. Here is a simple fix:
private PCamera camera = new PCamera(); {
PRoot root = new PRoot();
root.addChild(camera);
camera.addLayer(layer1);
camera.addLayer(layer2);
camera.addLayer(layer3);
}
That results in:
For reference here is a copy from PUtil.createBasicScenegraph() that creates a basic camera.
public static PCamera createBasicScenegraph() {
final PRoot root = new PRoot();
final PLayer layer = new PLayer();
final PCamera camera = new PCamera();
root.addChild(camera);
root.addChild(layer);
camera.addLayer(layer);
return camera;
}
Related
import java.awt.*;
import javax.swing.*;
public class O2BIntro extends Open2Beat {
private JLabel screenGraphic;
private ImageIcon introBackground;
private ImageIcon titleImage;
private ImageIcon startButtonImg;
private ImageIcon settingButtonImg;
private ImageIcon buttonSelectedImg;
public O2BIntro() {
introBackground = new ImageIcon(this.getClass().getResource("../img/wp2537453-dj-background-hd.jpg"));
titleImage = new ImageIcon(this.getClass().getResource("src/img/open2BeaTTitle.png"));
startButtonImg = new ImageIcon(this.getClass().getResource("src/img/MenuImg_Gamestart_KR.png"));
settingButtonImg = new ImageIcon(this.getClass().getResource("src/img/MenuImg_Preference_KR.png"));
}
public void paintIntro() {
screenGraphic = new JLabel(introBackground,JLabel.CENTER);
screenGraphic.setBounds(0, 0, DisplayBasic.myScreenWidth, DisplayBasic.myScreenHeight);
add(screenGraphic);
}
}
So, this is my current part of code. I tried to load my images from /src/img/, but it still doesn't display anything. How should I edit my code? Which kind of framework or component should I use to display properly?
i'm looking for a system to render this animation of the line dynamic with variable change:
public class FXMLDocumentController implements Initializable {
private long batt = 0;
#FXML
private Line lancettaBatteria;
public long mappa(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
#Override
public void initialize(URL url, ResourceBundle rb) {
Random random = new Random();
batt = random.nextInt(100);
long valMappatoBatteria = this.mappa(batt, 0, 100, -40, 135);
Rotate rotazioneBatteria = new Rotate();
lancettaBatteria.getTransforms().add(rotazioneBatteria);
Timeline timelineBatteria = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(rotazioneBatteria.angleProperty(), -40)),
new KeyFrame(Duration.seconds(3), new KeyValue(rotazioneBatteria.angleProperty(), valMappatoBatteria)));
timelineBatteria.play();
}
with this code it show only the first random number, my target is to move the line for infinite time with the relative random number generated(i need the random number for display the line in particular position), is this possible? i try to sorround all with a while(true)
public void initialize(URL url, ResourceBundle rb) {
while(true){
Random random = new Random();
batt = random.nextInt(100);
long valMappatoBatteria = this.mappa(batt, 0, 100, -40, 135);
Rotate rotazioneBatteria = new Rotate();
lancettaBatteria.getTransforms().add(rotazioneBatteria);
Timeline timelineBatteria = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(rotazioneBatteria.angleProperty(), -40)),
new KeyFrame(Duration.seconds(3), new KeyValue(rotazioneBatteria.angleProperty(), valMappatoBatteria)));
timelineBatteria.play();
}
}
but the app stop to work.
General Approaches
In general, an infinite animation in Java can be achieved multiple ways.
Here are a few:
Set the cycle count to indefinite to have an animation play forever:
Timeline.setCycleCount(Timeline.INDEFINITE);
Also setAutoReverse to true if you want it to go back and forth.
Use an AnimationTimer.
Use a Timeline and add an onFinished handler to the timeline which updates some relevant Keyframes within the timeline as necessary and then plays the timeline from start again.
The third approach of using an onFinishedHandler is the approach followed in the specific example below.
Specific Example
This example is based upon the requirements of your question as I understand them. I have no idea what why you are trying to do this. But as far as I understand what you are trying to do, the following app will do it.
Start position of each rotation:
Random max position of a rotation:
What it does is create a timeline which will update a value in a rotation transform for a line continuously. The line starts from a starting rotation angle, animates to a random maximum value and then animates back. Once the line reaches its starting position, a new random maximum value for the rotation is generated and the line animates to this new maximum value and back again. The process continues indefinitely. The setOnFinishedHandler of the timeline animation is the point which calculates the new random maximum value and updates the keyframe for the maximum animation value appropriately.
So that may or may not be exactly what you are trying to do, but perhaps it is enough for you to implement what you need.
import javafx.animation.*;
import javafx.application.Application;
import javafx.beans.property.*;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.util.Random;
public class VariableLine extends Application {
private static final double S = 100;
#Override
public void start(Stage stage) throws Exception {
RandomRotator randomRotator = new RandomRotator();
Line line = new Line(0, S, S, S);
randomRotator.getRotate().setPivotY(S);
line.getTransforms().add(randomRotator.getRotate());
Label maxValueText = new Label(randomRotator.getMaxAngle() + "");
maxValueText.textProperty().bind(randomRotator.maxAngleProperty().asString());
stage.setScene(new Scene(new Pane(maxValueText, line), S, S * 2));
stage.show();
randomRotator.getTimeline().play();
}
public static void main(String[] args) {
launch(args);
}
}
class RandomRotator {
private static final Random random = new Random(42);
private static final double INIT_ANGLE = -40;
private static final double MAX_ANGLE = 90;
private static final Duration ROTATION_DURATION = Duration.seconds(3);
private final ReadOnlyDoubleWrapper maxAngle = new ReadOnlyDoubleWrapper(INIT_ANGLE);
private final Timeline timeline = new Timeline();
private final Rotate rotate = new Rotate(INIT_ANGLE);
RandomRotator() {
timeline.getKeyFrames().addAll(
new KeyFrame(
Duration.seconds(0),
new KeyValue(rotate.angleProperty(), INIT_ANGLE)
),
new KeyFrame(
ROTATION_DURATION.divide(2),
new KeyValue(rotate.angleProperty(), maxAngle.get())
),
new KeyFrame(
ROTATION_DURATION,
new KeyValue(rotate.angleProperty(), INIT_ANGLE)
)
);
timeline.setOnFinished(event -> {
maxAngle.set(random.nextInt((int) MAX_ANGLE));
timeline.getKeyFrames().set(
1,
new KeyFrame(
ROTATION_DURATION.divide(2),
new KeyValue(rotate.angleProperty(), maxAngle.get())
)
);
timeline.playFromStart();
});
}
Rotate getRotate() {
return rotate;
}
public double getMaxAngle() {
return maxAngle.get();
}
public ReadOnlyDoubleProperty maxAngleProperty() {
return maxAngle.getReadOnlyProperty();
}
public Timeline getTimeline() {
return timeline;
}
}
I currently have a 3 class java application, I am trying to create a simple game using JavaFX. In My GameCore class I am trying to create an instance of gameGrid. but when I use "grid = new gameGrid(int, int, int, int);" eclipse tells me gameGrid is undefined and suggests I create the method, when I do as eclipse asks, it places a private method gameGrid in my gameCore class, but gameGrid is supposed to be the constructor for gameGrid.class. I have already restarted the project and cleaned the project to no avail.
public class gameCore {
gameGrid grid;
public gameCore(){
getGrid();
}
public void getGrid(){
grid = gameGrid(32, 32, 10, 10); //Error is here, underlining "gameGrid"
//Also using gameGrid.gameGrid(32,32,10,10); does not work either, still says its undefined
/*
This is the code that Eclipse wants to place when I let it fix the error, and it places this code in this class.
private gameGrid gameGrid(int i, int j, int k, int l) {
// TODO Auto-generated method stub
return null;
}
*/
}
}
public class gameGrid {
protected int[][] grid;
protected int tileWidth;
protected int tileHeight;
public gameGrid(int tileWidth, int tileHeight, int horizTileCount, int vertTileCount){
//Create Grid Object
grid = new int[vertTileCount][];
for(int y = 0; y < vertTileCount; y++){
for(int x = 0; x < horizTileCount; x++){
grid[y] = new int[horizTileCount];
}
}
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
}
}
import java.awt.Dimension;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class gameGUI extends Application {
Dimension screenDimensions = new Dimension(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
public static void main(String[] args){
launch(args);
}
public void start(Stage stage) throws Exception {
Canvas c = new Canvas();
StackPane sp = new StackPane();
Scene scene = new Scene(sp, screenDimensions.width, screenDimensions.height);
sp.getChildren().add(c);
stage.setScene(scene);
gameCore game = new gameCore();
stage.show();
}
}
What you are missing is "new" for instantiation, i. e. you need to write
grid = new gameGrid(32, 32, 10, 10);
In Java classes start with uppercase character, you should read the guidelines.
In case you want to see a grid being done in JavaFX with java nodes instead of a canvas, you can look at the code of the question I asked recently.
I am making a game in the jMonkey Engine 3 and my world generation code was a bit bulky so I planned to move it to a new class called Generator but when I finally got everything worked out and ran my program, I got a NullPointerException in the place where I tried to use the method from the other class. I have had such bad luck with NullPointerException in the past but this is the worst one yet. The code worked when it was in the main class file. I will give you the code for both classes below as well as the error.
Please note that I am not including the package declaration or the imports to save space.
Class one: Main:
public class Main extends SimpleApplication implements ActionListener {
private static final Logger logger = Logger.getLogger(Main.class.getName());
private BulletAppState bulletAppState;
private CharacterControl playerControl;
private Vector3f walkDirection = new Vector3f();
private boolean[] arrowKeys = new boolean[4];
private CubesSettings cubesSettings;
private BlockTerrainControl blockTerrain;
private Node terrainNode = new Node();
private Generator gen;
public static void main(String[] args){
Logger.getLogger("").setLevel(Level.FINE);
AppSettings s = new AppSettings(true);
Main app = new Main();
try {
s.load("com.bminus");
} catch(BackingStoreException e) {
logger.log(Level.SEVERE, "Could not load configuration settings.",e);
}
try {
s.setIcons(new BufferedImage[]{ImageIO.read(new File("assets/Textures/icon.gif"))});
} catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Icon file missing",e);
}
s.setRenderer(AppSettings.LWJGL_OPENGL2);
s.setBitsPerPixel(24);
s.setFrameRate(-1);
s.setFullscreen(false);
s.setResolution(640,480);
s.setSamples(0);
s.setVSync(true);
s.setFrequency(60);
s.setTitle("The Third Power Pre-Alpha 1.1.0");
try {
s.save("com.bminus");
} catch(BackingStoreException e) {
logger.log(Level.SEVERE, "Could not save configuration settings.",e);
}
app.setShowSettings(false);
app.setSettings(s);
app.start();
}
public Main(){}
#Override
public void simpleInitApp(){
setDisplayFps(false);
setDisplayStatView(false);
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
initControls();
gen.initBlockTerrain(); //THIS LINE IS THE ONE THAT IS NULL!!!
initGUI();
initPlayer();
cam.lookAtDirection(new Vector3f(1, 0, 1), Vector3f.UNIT_Y);
}
private void initControls(){
inputManager.addMapping("fps_show", new KeyTrigger(KeyInput.KEY_F3));
inputManager.addMapping("fps_hide", new KeyTrigger(KeyInput.KEY_F4));
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("forward", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("backward", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("jump", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("place", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("break", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(this, "fps_show");
inputManager.addListener(this, "fps_hide");
inputManager.addListener(this, "left");
inputManager.addListener(this, "right");
inputManager.addListener(this, "forward");
inputManager.addListener(this, "backward");
inputManager.addListener(this, "jump");
inputManager.addListener(this, "place");
inputManager.addListener(this, "break");
}
private void initGUI(){
BitmapText crosshair = new BitmapText(guiFont);
crosshair.setText("+");
crosshair.setSize(guiFont.getCharSet().getRenderedSize() * 2);
crosshair.setLocalTranslation(
(settings.getWidth() / 2) - (guiFont.getCharSet().getRenderedSize() / 3 * 2),
(settings.getHeight() / 2) + (crosshair.getLineHeight() / 2), 0);
guiNode.attachChild(crosshair);
BitmapText instructionsText1 = new BitmapText(guiFont);
instructionsText1.setText("Left Click: Remove");
instructionsText1.setLocalTranslation(0, settings.getHeight(), 0);
guiNode.attachChild(instructionsText1);
BitmapText instructionsText2 = new BitmapText(guiFont);
instructionsText2.setText("Right Click: Place");
instructionsText2.setLocalTranslation(0, settings.getHeight() - instructionsText2.getLineHeight(), 0);
guiNode.attachChild(instructionsText2);
BitmapText instructionsText3 = new BitmapText(guiFont);
instructionsText3.setText("Bottom Layer Cannot Be Broken");
instructionsText3.setLocalTranslation(0, settings.getHeight() - (2 * instructionsText3.getLineHeight()), 0);
guiNode.attachChild(instructionsText3);
}
private void initPlayer(){
playerControl = new CharacterControl(new CapsuleCollisionShape((cubesSettings.getBlockSize() / 2), cubesSettings.getBlockSize() * 2), 0.05f);
playerControl.setJumpSpeed(25);
playerControl.setFallSpeed(140);
playerControl.setGravity(100);
playerControl.setPhysicsLocation(new Vector3f(5, 257, 5).mult(cubesSettings.getBlockSize()));
bulletAppState.getPhysicsSpace().add(playerControl);
}
#Override
public void simpleUpdate(float lastTimePerFrame) {
float playerMoveSpeed = ((cubesSettings.getBlockSize() * 2.5f) * lastTimePerFrame);
Vector3f camDir = cam.getDirection().mult(playerMoveSpeed);
Vector3f camLeft = cam.getLeft().mult(playerMoveSpeed);
walkDirection.set(0, 0, 0);
if(arrowKeys[0]){ walkDirection.addLocal(camDir); }
if(arrowKeys[1]){ walkDirection.addLocal(camLeft.negate()); }
if(arrowKeys[2]){ walkDirection.addLocal(camDir.negate()); }
if(arrowKeys[3]){ walkDirection.addLocal(camLeft); }
walkDirection.setY(0);
playerControl.setWalkDirection(walkDirection);
cam.setLocation(playerControl.getPhysicsLocation());
}
#Override
public void onAction(String actionName, boolean value, float lastTimePerFrame){
if(actionName.equals("forward")) {
arrowKeys[0] = value;
}
else if(actionName.equals("right")) {
arrowKeys[1] = value;
}
else if(actionName.equals("left")) {
arrowKeys[3] = value;
}
else if(actionName.equals("backward")) {
arrowKeys[2] = value;
}
else if(actionName.equals("jump")) {
playerControl.jump();
}
else if(actionName.equals("fps_show")) {
setDisplayFps(true);
}
else if(actionName.equals("fps_hide")) {
setDisplayFps(false);
}
else if(actionName.equals("place") && value){
Vector3Int blockLocation = getCurrentPointedBlockLocation(true);
if(blockLocation != null){
blockTerrain.setBlock(blockLocation, Block_Wood.class);
}
}
else if(actionName.equals("break") && value){
Vector3Int blockLocation = getCurrentPointedBlockLocation(false);
if((blockLocation != null) && (blockLocation.getY() > 0)){
blockTerrain.removeBlock(blockLocation);
}
}
}
private Vector3Int getCurrentPointedBlockLocation(boolean getNeighborLocation){
CollisionResults results = getRayCastingResults(terrainNode);
if(results.size() > 0){
Vector3f collisionContactPoint = results.getClosestCollision().getContactPoint();
return BlockNavigator.getPointedBlockLocation(blockTerrain, collisionContactPoint, getNeighborLocation);
}
return null;
}
private CollisionResults getRayCastingResults(Node node){
Vector3f origin = cam.getWorldCoordinates(new Vector2f((settings.getWidth() / 2), (settings.getHeight() / 2)), 0.0f);
Vector3f direction = cam.getWorldCoordinates(new Vector2f((settings.getWidth() / 2), (settings.getHeight() / 2)), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
node.collideWith(ray, results);
return results;
}
public void attachRootChildTerrain(){ //THIS IS CALLED IN THE GENERATOR CLASS!!
rootNode.attachChild(gen.terrainNode);
}
}
Class two: Generator:
public class Generator {
private CubesSettings cubesSettings;
private BlockTerrainControl blockTerrain;
private final Vector3Int terrainSize = new Vector3Int(1000, 256, 1000);
private final Vector3Int bottomLayer = new Vector3Int(1000,1,1000);
private BulletAppState bulletAppState;
public Node terrainNode = new Node();
private SimpleApplication sa;
private Main main;
public void initBlockTerrain(){
CubesTestAssets.registerBlocks();
CubesTestAssets.initializeEnvironment(sa);
cubesSettings = CubesTestAssets.getSettings(sa);
blockTerrain = new BlockTerrainControl(cubesSettings, new Vector3Int(7, 1, 7));
blockTerrain.setBlocksFromNoise(new Vector3Int(), terrainSize, 20f, Block_Grass.class);
blockTerrain.setBlocksFromNoise(new Vector3Int(), bottomLayer, 0.0f, Block_Stone.class);
blockTerrain.addChunkListener(new BlockChunkListener(){
#Override
public void onSpatialUpdated(BlockChunkControl blockChunk){
Geometry optimizedGeometry = blockChunk.getOptimizedGeometry_Opaque();
RigidBodyControl rigidBodyControl = optimizedGeometry.getControl(RigidBodyControl.class);
if(rigidBodyControl == null){
rigidBodyControl = new RigidBodyControl(0);
optimizedGeometry.addControl(rigidBodyControl);
bulletAppState.getPhysicsSpace().add(rigidBodyControl);
}
rigidBodyControl.setCollisionShape(new MeshCollisionShape(optimizedGeometry.getMesh()));
}
});
terrainNode.addControl(blockTerrain);
terrainNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
main.attachRootChildTerrain();
}
}
The error:
java.lang.NullPointerException
at com.bminus.Main.simpleInitApp(Main.java:110)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
This is the first time I have tried to use multiple classes. I am guessing I forgot to call something from the Generator class or make something public instead of private but I'm not sure. If anyone can figure this out, it would be greatly appreciated. Thanks!
EDIT: I did what you guys suggested (I think) and I got this error:
Exception in thread "main" java.lang.StackOverflowError
at sun.misc.Unsafe.putObject(Native Method)
at java.util.concurrent.ConcurrentLinkedQueue$Node.<init>(ConcurrentLinkedQueue.java:187)
at java.util.concurrent.ConcurrentLinkedQueue.<init>(ConcurrentLinkedQueue.java:255)
at com.jme3.app.Application.<init>(Application.java:94)
at com.jme3.app.SimpleApplication.<init>(SimpleApplication.java:102)
at com.jme3.app.SimpleApplication.<init>(SimpleApplication.java:98)
at com.bminus.Main.<init>(Main.java:88)
at com.bminus.Generator.<init>(Generator.java:31)
at com.bminus.Main.<init>(Main.java:47)
and since it is an overflow error the last two error lines go on FOREVER! The lines in my code that are being called as errors are:
public Main(){}
,
private Main main = new Main();
and
private Generator gen = new Generator(this);
I don't know exactly why this is happening but if any of you guys did, it would be great to know how to fix it. Thanks!
Most important when debugging NullPointerException's is to find the line that throws the exception. A variable that you are trying to use on that line is null.
Possible culprits:
In your Main class, your Generator variable, gen, is never assigned an instance, and thus is null. Give it an instance by calling the Generator constructor.
gen = new Generator();
In your Generator class, the Main field, main, is null since you never assign to it a Main instance. I suggest that you give the constructor a Main parameter so you can pass in the currently used Main instance created in your main method (these names are confusing!) into your Generator class and use this parameter to initialize your main field.
i.e.,
public Generator(Main main) {
//.....
this.main = main; // give the main field an object
}
So change the above code to create Generator to:
gen = new Generator(this);
I am using Eclipse/Java 7. I have a class, which gets some values from queries and saves them in the 2 dimensional array path. Then I have made another class which designs 2 linked blocks. What I want to do is get the values of path1[0] and path[2][0] etc from the first class and automatically place them in the designed blocks. Any ideas how to do it? Thanks in advance
Example
1st class (results from queries):
public class OntoQ extends JFrame {
public static void main(String[] args) {
String[][] path = new String[20][2];
int pathi = 0;
int pathj = 0;
....
2nd class (design):
import javax.swing.JFrame;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
public class Design extends JFrame {
public Design() {
super("Test");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try
{
Object v1 = graph.insertVertex(parent, null, "path[1][0]", 20, 20, 80,
30);
Object v2 = graph.insertVertex(parent, null, "path[2][0]" , 240, 150,
80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
}
finally
{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
add(graphComponent);
}
public static void main(String[] args)
{
Design frame = new Design();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}