I'm currently getting started on a project where I use a grid for a game (Dot game, but that's not very important). Basically, it will be a grid of dots, where a player can click on the lines between the dots (like this).
I currently am using a JFrame, and was thinking about ways I could populate it with JPanel components to create clickable regions. Currently, I was thinking about trying to create for loops to correctly populate it, but I don't know how I could efficiently do this.
Any recommendations for how to do this? I'm not asking people to write code for me, just point me in the right direction. Is there any layout (GridLayout?) that would work well for this?
Welp, I ended up figuring it out on my own, but using a soulution not quite ideal. I have a for loop making every odd line have a black panel, then clickable jbutton, then a black panel, etc. Every even line has a clickable j button, then a white middle pannel, then a clickable jbutton, etc.
Looks like this:
https://gyazo.com/79b80dfe13b017a234e6fad2aa224d58
Related
I've made an equation builder program. it displays the terms with textboxes and buttons in a single line. each control is a term 3 * 3 is 2 textboxes for the numbers and a button for the *. I would like drag and drop to be implemented for changing the order of these. I'm just missing on crucial part I need to know how to detect where the control is dropped, either on the jpanel they are in or if dropped on a jbutton which physical part of the jbutton. Basically I just need to know whether to put it on the left or the right.
I currently have it kind of working where when you start to drag I make little catcher buttons appear in between each control but honestly it looks like crap and doesn't work that well.
I'm currently trying to learn JavaFX and FXML (and Java) and decided to write a textbased RPG. The basis for this was already written quite some time ago, but now I wanted to do the whole thing better. Including the visuals, that is, the GUI.
First of all: I'd like to do this using FXML. That does not mean however that I'm not interested in seeing a way using basic Java.
What I want to build is a fully dynamic GUI. No Matter how it is resized, the components (and ideally the text as well) would be at the same location, relative to the other components / window border.
The window would have some kind of top line with several buttons for saving, the menu, overview and whatnot. Below that, on the left side, would be Character information: Health, Experience, Money etc. On the right side would be the text output (using a Scrollpane) plus a text field, for user input. Below the text input/output I'd place the buttons used for actions and decisions. Bottom left corner does not contain anything, though it should be a separate area.
At first I tried using Splitpanes, not knowing that they can be resized anytime and have visible Dividers. Now I'm not sure what to do.
A Gridpane would give some of the functionality I need (separate the areas), but also does not give the flexibility I want (unless I just don't know how to do it). I couldn't get it to work. So I tried using simple Panels. But with them I couldn't figure out how to keep the panels keep their relative position and size, and how to make the Buttons stick to the borders.
So what would be the best way to go about this? GridPane? Panel? Something else I'm missing? Since I don't really know how to achieve this, any help in any direction would be highly appreciated.
Have you read the layout tutorial?
From your description, it sounds like a BorderPane might be best for the overall layout (i.e. the root of your scene graph): I'm not quite sure if you could easily make this give you the empty bottom left corner you want. Alternatively you could use a GridPane as you suggested, with appropriate ColumnConstraints and RowConstraints applied to size the cells in the pane.
I am stuck trying to make the following kind of slide menu in Swing.
I have searched entire web but I didn't find any tutorial or maybe I missed that. Can you please suggest a solution or a tutorial? I don't need code but just the components to use.
This is very simple in Swing.
What you are looking for is a JSplitPane. You can start with it closed and it has arrows (or other symbols depending on your look and feel) that can be clicked on.
http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html
Note: A slider is a very different component. (http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html)
Edit: Based on your comment it sounds like actually are looking for an animated opening of the slider (which is hard to tell from a static image).
In that case this question is a duplicate, look here: Animation for divider movement in JSplitPane
I have probably a quick question but here it goes. I am making a game (new to programming) and I want a text field in the middle of my game that I can easily add to kind of like a console. You will be able to view the beginning from late into the game.
Example:
Welcome to the game.
Added when you click a button
More text is added.
You click a different button
More text is added.
I am currently using a JLabel for this but it's a .setText which is inconvenient when I want to have tons of text throughout my game. As well, how could I add a scrollbar to this?
I'd guess you are looking for JTextArea .
I am working on a homework so i am not asking for code, i am trying to make this by myself. by the way, i am stuck again with the GUI part and have little problems with code part. first things is about button size and image size. i didnt use methods for size of buttons just set the image as an icon for the button. but as you see below, buttons dont fit the image.
second thing is how can i first disable the icon and when user presses to button it will reveal the icon ?. and how can i embed 8 pictures in a loop? can i create an array for images... i appreciate if you can help me. and thanks anyway : )
I'd start with How to Use Buttons. JToggleButton works well for this, as you can change the Icon in an ItemListener based on the button's selected state. Examples may be found here and here.