Hi, ich möchte in ein Textfield die größe eines Floats eingeben, und den Float als größe einer Figur verwenden, also bitte wie kann ich das machen?
Irgendwie funktioniert das ganze nicht
Wenn ihr mir bitte bei dem float "headsize" helfen könntet, den rest kann ich dann selber machen, danke schon mal im Voraus Developer_X!
Irgendwie funktioniert das ganze nicht
Wenn ihr mir bitte bei dem float "headsize" helfen könntet, den rest kann ich dann selber machen, danke schon mal im Voraus Developer_X!
Code:
public class Rayman_Maker extends JFrame
{
URL url = null;
AudioClip clip;
private String DateiTypS;
private String DateiT;
JMenu help = new JMenu("Hilfe");
static int outFileSeq = 0;
static String outFileBase = "ScreenShot";
static NumberFormat nf = NumberFormat.getInstance();
private Color backcolor = Color.cyan;
private Color forecolor = Color.blue;
////////////////Head/////////////////
private float hx,hy,hz=0;
private Transform3D head;
private TransformGroup Head;
private float headsize=1;
private float rhx,rhy,rhz;
private Transform3D rh1;
private Transform3D rh2;
private Transform3D rh3;
private TransformGroup Rh1;
private TransformGroup Rh2;
private TransformGroup Rh3;
//////////////////////////////////////////////////////////////////////////////////////
public Rayman_Maker()
{
Toolkit tk = Toolkit.getDefaultToolkit();
final Dimension d = tk.getScreenSize();
setSize(d.width,d.height);
setVisible(true);
setIconImage(new ImageIcon("F:/Rayman_Maker_1.0/Icon.jpg").getImage());
setLayout(null);
setVisible(true);
setResizable(false);
setTitle("Rayman_Maker_1.0");
final JMenuBar menubar = new JMenuBar();
menubar.setBounds(0,0,1200,20);
menubar.setBackground(backcolor);
add(menubar);
final JMenuBar menubar2 = new JMenuBar();
menubar2.setBounds(1200,0,1000,20);
menubar2.setBackground(backcolor);
add(menubar2);
///////////////////////////////////////////
JButton b = new JButton();
b.setBackground(backcolor);b.setBounds(1000,70,100,20);add(b);b.setForeground(forecolor); b.setLabel("Head");
JButton b1 = new JButton();
b1.setBackground(backcolor);b1.setBounds(1000,90,100,20);add(b1);b1.setForeground(forecolor);b1.setLabel("Kopf-Größe");
final JTextField b11 = new JTextField();
b11.setBackground(backcolor);b11.setBounds(1100,90,100,20);add(b11);b11.setForeground(forecolor);
JButton b111 = new JButton();
b111.setBackground(backcolor);b111.setBounds(1200,90,200,20);add(b111);b111.setForeground(forecolor);b111.setLabel("Kopf-Größe aktualisieren");
b111.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)
{ headsize = Integer.parseInt(b11.getText()); }});
//Translation
JButton trans = new JButton();
trans.setBackground(backcolor);trans.setBounds(1000,110,150,20);add(trans);trans.setForeground(forecolor);trans.setLabel("Kopf Position (x,y,z)");
//
final JButton transx = new JButton();
transx.setBackground(backcolor);transx.setBounds(1150,110,45,20);add(transx);transx.setForeground(forecolor);transx.setLabel("X");
final JTextField tae = new JTextField();
tae.setBackground(backcolor);tae.setBounds(1195,110,25,20);add(tae);tae.setForeground(forecolor);
//
final JButton transy = new JButton();
transy.setBackground(backcolor);transy.setBounds(1215,110,45,20);add(transy);transy.setForeground(forecolor);transy.setLabel("Y");
final JTextField tae1 = new JTextField();
tae1.setBackground(backcolor);tae1.setBounds(1260,110,25,20);add(tae1);tae1.setForeground(forecolor);
//
final JButton transz = new JButton();
transz.setBackground(backcolor);transz.setBounds(1285,110,45,20);add(transz);transz.setForeground(forecolor);transz.setLabel("Z");
final JTextField tae2 = new JTextField();
tae2.setBackground(backcolor);tae2.setBounds(1330,110,25,20);add(tae2);tae2.setForeground(forecolor);
JButton po = new JButton("Position aktualisieren");
add(po); po.setBounds(1000,130,200,20); po.setForeground(forecolor); po.setBackground(backcolor);
po.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e)
{hx = Integer.parseInt(transx.getText());hy = Integer.parseInt(transy.getText());hz = Integer.parseInt(transz.getText());head = new Transform3D();Head=new TransformGroup();head.setTranslation(new Vector3f(hx,hy,hz));Head.setTransform(head);}});
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
add(canvas);
canvas.setBounds(0,90,1000,780);
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.addBranchGraph(scene);
Point3d p = new Point3d();
BoundingSphere bounds = new BoundingSphere(p,10);
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
void createStarBackground(BranchGroup bg)
{
java.util.Random rand = new java.util.Random();
float mag;
BranchGroup BGBranch=new BranchGroup();
Background BG=new Background();
PointArray starfield = new PointArray(15000, PointArray.COORDINATES|PointArray.COLOR_3);
float[] point = new float[3];
float[] brightness = new float[3];
for (int i = 0; i < 15000; i++)
{
point[0] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
point[1] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
point[2] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
starfield.setCoordinate(i, point);
mag=(rand.nextFloat()+0.5f)/1.5f;
brightness[0]=mag;
brightness[1]=mag;
brightness[2]=mag;
starfield.setColor(i, brightness);
}
Shape3D StarShape=new Shape3D(starfield);
StarShape.setAppearance(new Appearance());
StarShape.getAppearance().setPointAttributes(new PointAttributes(1f,true));
BGBranch.addChild(StarShape);
BG.setGeometry(BGBranch);
BG.setApplicationBounds(new BoundingSphere(new Point3d(),10.0));
BG.setColor(new Color3f(0,0,0));
bg.addChild(BG);
}
public BranchGroup createSceneGraph()
{
BranchGroup Root = new BranchGroup();
createStarBackground(Root);
//Head
head = new Transform3D();
head.setTranslation(new Vector3f(hx,hy,hz));
Head = new TransformGroup();
Root.addChild(Head);Head.setTransform(head); Head.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
rh1 = new Transform3D(); rh1.rotX(Math.toRadians(rhx));
Rh1 = new TransformGroup(); Head.addChild(Rh1);Rh1.setTransform(rh1);
rh2 = new Transform3D(); rh2.rotY(Math.toRadians(rhy));
Rh2 = new TransformGroup(); Rh1.addChild(Rh2);Rh2.setTransform(rh2);
rh3 = new Transform3D(); rh3.rotZ(Math.toRadians(rhz));
Rh3 = new TransformGroup();Rh3.addChild(new Rayman_Head(headsize).getChild()); Rh3.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE|TransformGroup.ALLOW_TRANSFORM_READ|TransformGroup.ALLOW_LOCALE_READ|TransformGroup.ALLOW_LOCAL_TO_VWORLD_READ|TransformGroup.ALLOW_COLLISION_BOUNDS_WRITE|TransformGroup.ALLOW_COLLIDABLE_READ|TransformGroup.ALLOW_BOUNDS_WRITE|TransformGroup.ALLOW_BOUNDS_READ|TransformGroup.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE|TransformGroup.ALLOW_AUTO_COMPUTE_BOUNDS_READ|TransformGroup.ALLOW_TRANSFORM_WRITE|TransformGroup.ALLOW_CHILDREN_READ|TransformGroup.ALLOW_CHILDREN_EXTEND);Rh2.addChild(Rh3);Rh3.setTransform(rh3);
//Light Definitions
Point3d p = new Point3d();
BoundingSphere bounds = new BoundingSphere(p, 100);
Color3f lightColor = new Color3f(.3f,.3f,.3f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
Root.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
Root.addChild(directionalLight);
return Root;
}
public static void main(String[]args){new Rayman_Maker();}
}
Zuletzt bearbeitet: