K
K
Kirill Romanenko2014-07-05 01:10:11
Java
Kirill Romanenko, 2014-07-05 01:10:11

What is the correct code to write in this case?

Hello everyone, dear programmers and not so much ))
I have a question about creating a small application and in general - about various gadgets that can be used in similar projects.
I'm new to Java, only 4 days old, but I decided to start by creating a simple mini-game - a text quest. At first I worked on the plot, the skeleton, I started writing dialogues, triggers, but now this is what I'm trying to do a shell. That is, menus, buttons for entering, exiting, etc.
My problem is this: I created a window, placed the buttons, the title is on top, but I needed to add one more text line just below. I did not know how to add a textArea to the frame, but I found one way - he did it (Label X :) but .. the line hangs in the middle of the screen AND NO COMMANDS I CAN SHIFT IT FROM THERE OR ANYWHERE ELSE! I went through different commands, functions, but - to no avail. what's wrong, or did I choose the wrong way to text?
Here is a snippet from the code with this place:
~~~
countLabel = new JLabel("\nKira Lis39 - Endless Autumn");//here is the name itself that hangs properly on top!
Label Hello = new Label("\n \n \n \nThank you for choosing us! ^_^ nya"); //and here's what I need to place BELOW it, not in the middle of the screen on the left!
Hello.setBackground(Color.getHSBColor(0.80f, 0.25f, 1));
Hello.setBounds(70, 100, 80, 20);//Neither this,
Hello.setLocation(50, 50);//Neither this...
Hello.setSize(50, 50);//Neither this - just NOT WORKS! no matter what I put in there and what numbers I didn’t write!
add(hello); //Adding a label to the applet
workspace newGame = new JButton("New Game");
saveGame = new JButton("Save");
loadGame = new JButton("Load");
~~~

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tsarevfs, 2014-07-05
@tsarevfs

Have n't tried that ?

D
Dmitry Arbuzov, 2014-07-05
@DmitryArbuzov

How components are arranged depends on the layout manager you are using.
In this case, setLayout(null) will help you. This means that no layout manager is used and all elements will use absolute sizes and positions. Just like in your code.
But for Java, this is the wrong approach. Because multiplatform technology. Components look different on different operating systems. Windows XP has one style, Windows 8 has another, and Mac OS has a third. And what looks right on one system may slip on another.
It is better to immediately read the theory with examples about all layout managers. There is little and everything is clear. Book "Head First Java" 13 chapter. It is in Russian.

K
Kirill Romanenko, 2014-07-05
@kiralis39

I have a new problem with this app! I just uploaded it to the jar, riveted the bat - everything generally works fine and the window starts up and the button works as it should .. But on the second computer where 32 bit 7 is written it is not compatible with this Windows - means no one else will read it except 64-bit machines
???

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question