Tile Based Map Editor - Organize Layout
Apr 13, 2014
I'm trying to program a tile-based map editor and most of it is going quite smoothly except trying to organize the layout. Originally I was going to use 2 frames, one for the map, and 1 for the tile set, but after reading about frames I learned that that is bad practice and is also inconvenient because there is no way to have both frames in focus at once (so you need to click an extra time to gain focus when switching windows). So what I'd like to do is create a single frame application that holds 3 panels. One for the map, one for the tile set, and one for tile settings. This is basically what it would look like:
Note that the tile settings panel uses GUI elements (a border, a JLabel (which starts out empty), a JComboBox, and a JTextField) while the other 2 panels are just drawing panels*
Now I have tried multiple things which either did not work visually (panels were inside panels) or did not compile. One thing I tried was using BoxLayout to put the 2 tile panels vertically within a temporary panel which I then tried to add into the frame after the map panel (with FlowLayout), but that made it look like this: I honestly don't know what else I did that I should write here because in retrospect many of the tings I tried were silly or I don't remember exactly what I did. What would be the best layout to doing what I want?
View Replies
ADVERTISEMENT
Jan 18, 2014
So the following is my code for the Terrian Generation of my game, however the way i have it rendering all the tile rectangles as opposed to just rendering whats visable on my JFrame causes lots of lag.
These are the variables and Rectangles inside _TerrianGen.class
//CHUNK
static int chunkx =2048;
static int chunky =2048;
//RECTANGLES
public static Rectangle[][] tile = new Rectangle[64][64];
static int[][] blockType = new int[64][64];
//0=Grass 1=Dirt 2=Stone 10=Brick 11=Coal 12=Iron 21=Gold 22=Diamond -1=null
This is the Init() code
for (int x =0; x < chunkx-32; x+=32){
for (int y=0; y < chunky-32; y+=32){
tile[y/32][x/32] = new Rectangle(x, y, 32, 32);
blockType[y/32][x/32] = -1;
[Code] ....
View Replies
View Related
Jun 1, 2014
I want to add only one button in a JFrame by using Mig Layout, dock south as BorderLayout.South does . Is it possible?
View Replies
View Related
Dec 16, 2014
When the tile loads it loads at the side where i wanted it to be and when my character falls down the image/tile stretches to the collision and stops. looks like this stretches.jpg
The character codes:
error.jpg
And for the Level:
error2.jpg
View Replies
View Related
Oct 5, 2014
So I can only get 1 tile to render Okay so now it's no tiles Nvm.
Window
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
[code]....
View Replies
View Related
Feb 20, 2014
package modern.gems;
public class Board {
// will need to add params where required ...
private Gem[][] gems;
private int[][] array;
private int rows;
private int cols;
[Code] ....
View Replies
View Related
Oct 8, 2014
If I wanted to take strings in from the user through a GUI say day, month, year. I am looking for a way to organize those incoming strings. I am going to add this information to a queue. However, I want the people who put in the earliest day, month, and year to be put into the queue first followed by the next earliest so on and so forth.I was thinking what I would need to make a method that would compare the information.
View Replies
View Related
Feb 16, 2015
When I run this (entering 12 for both questions) I get this error:
java.lang.ArrayIndexOutOfBoundsException: 12
at MathTablesTwo.main(MathTablesTwo.java:22)
Also, what would be the proper way to organize my code into blocks?
import java.util.Scanner;
public class MathTablesTwo {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
Apr 13, 2014
I am trying to write a program that read from a csv file called matches.csv.
A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case of draw each of the two teams get 1 point.
For example, the first line of the file matches.txt is as follow:
In the file it contains the following data.
17/08/2013ArsenalAston Villa13
24/08/2013Aston VillaLiverpool01
This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points.
How can I structure my output to make it make it read
Position Team Played Points
1 Aston Villa 2 3
2 Liverpool 1 3
3 Arsenal 1 0
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Teams {
public static void main(String[] args) {
String fileName = "matches.csv";
File file = new File(fileName);
[code]....
View Replies
View Related
Oct 7, 2014
Lately I've been working with JDBC and writing queries in some Java programs. I've noticed that I keep experimenting with where I place my blocks of querying code. I've tried creating a private method in the class where the query is used, I've created utility classes where I can call the query when needed, and sometimes I've just put it in a localized block of code where I need to. Also, most often these queries are one-shot queries where I need to pull the data to populate a JTable.
In short, this has made me realize that I don't have a solid practice for organizing my queries in Java. So my question is "Is there a practice for organizing query code?".
View Replies
View Related
Aug 15, 2014
I have a couple of objects, which I will call height and width. The latter may depend on the former and I access them through an interface:
interface Height
{
double getHeight();
}
interface Width
{
double getWidth( Height height );
}
I then have something I will call a RectangleMaker, which represents some set of rectangles that can be made. It takes a list of heights and widths and keeps track of which ones have been selected and which ones can still be made. For example, the possible heights might be 2 or 3 and the possible widths 3 or 4. It needs to determine if it can make a rectangle with a specific area and if selected to make that rectangle, disallow any other heights. So if I said, you are in charge of 2 x 3 rectangles, it could still potentially also make 2 x 4 rectangles, but 3 x 3 rectangles would no longer be an option. For the most part I think these details are irrelevant to my question, which is really about organization and assignment of responsibilities.
interface RectangleMaker
{
void setHeights( ArrayList<Height> );
void setWidths( ArrayList<Width> );
boolean isAreaAvailable( double Area );
void selectDimension( Height height, Width width );
Height listAllowedHeight();
ArrayList<Width> listAllowedWidths();
}
Now I have a new requirement. The lists of heights now need to be associated with a source, as do the widths. I should keep track of a list of RectangleMakers and pick the 'most appropriate' one for a particular area. The rule is to sort first on the height source and then on the width source and the first one able to handle the area, gets the job. So I created two enums heightSource and widthSource and had RectangleMaker implement Comparable, so I can make an ArrayList<RectangleMaker> and sort it based on the rules. Then I traverse the list and the first one that returns isAreaAvailable() true gets the job.
The final bit is that these sources also imply a specific set of Heights or Widths. How I get that set varies, it may be a fixed value or values, or might be read from a file. So in principle I could have:
ArrayList<Height> buildHeights( RectangleMaker.SOURCE source )
{
switch ( source )
{
}
}
and have a lot of specific code that builds each list by whatever method is appropriate. I still need to deal with the fact I might need additional information to build the lists. For example, one source might require a min, max and increment and another might require a file name. So I started working in the direction of more interfaces.
interface HeightList
{
ArrayList<Height> getHeights();
RectangleMaker.Source getSource();
}
I am not totally comfortable with my enum lists. They solve the sorting problem, but I am not exactly sure which class should define them. Right now they are defined by the RectangleMaker. I would need to update this class every time I added an implementation of HeightList or WidthList.
I was also thinking that since the list is built from a specific source, that source should be associated with the list. That would lead me to make this change:
interface RectangleMaker
{
void setHeights( HeightList heightList );
void setWidths( WidthList widthList );
boolean isAreaAvailable( double Area );
void selectDimension( Height height, Width width );
Height listAllowedHeight();
ArrayList<Width> listAllowedWidths();
}
It seems maybe there should be a factory in here somewhere, but this is where I am having trouble sorting out exactly who has what responsibility. I can do this sort of thing with my HeightList interface:
class SpacedHeight implements HeightList
{
int start;
int end;
int step;
ArrayList<Height> heights;
RectangleMaker.SOURCE source;
[Code] ....
Should I be thinking of putting one more layer over all of this? What complicates my thinking are two things: multiple instances may have the same source and some of these instances are dynamic. For example, two SpacedHeight instances may have different ranges, but they are both SpacedHeight and it doesn't matter which gets picked first. Exactly what SpacedHeight instances get created is determined by prompting the user for the values. If the heights come from a file, every instance would be associated with a different source and the file names would be hard-coded.
I think I want to make a HeightFactory and I think then it would make sense to move my enum definitions there. I see how I would do that if I could hard-code a specific instance of a HeightList with a specific enum. I am less clear on how to handle the case where the factory needs different parameters for different HeightList implementations.
View Replies
View Related
Mar 20, 2014
I'm currently taking a computer program design class which has done a lot for my understanding of how to organize classes, but isn't giving me challenging enough assignments and I don't believe it's going to be covering interfaces and abstract classes, which is a shame. So I've been digging into these topics myself and decided to work on my own program (an Uno game program) that would utilize everything we've been learning and give me some practice with GUIs.
My current plan:
Have an abstract UnoCard class that determines the basic properties/methods common to all cards. Create a class for each card type extending from UnoCard, which would be - the generic card (number and color), action cards (skip, reverse, draw two), and special cards (wild, wild draw four, and blank).
Two enums, one for color, one for rank (which includes the numbers, as well as the action and special card ranks (reverse, wild, exc.) ).
A deck class would have an ArrayList <UnoCard> property and it's constructor would initialize a fresh deck.
A hand class that also has an ArrayList <UnoCards> where it gets said cards from the deck class.
A discard pile class, which contains the cards discarded and the current card in play.
A "board" class (haven't figured out a better name for it yet) which would determine/keep track of the number of players/hands, the turn order, the locations of the cards, and the winning condition.
Area of confusion and concern I'm having:
From what I've read, I want to avoid circular dependency. So if that's the case, when a card type effects the state of a "hand" or the turn order or really anything else, then in what class do I place the method(s) that effect that? If I place it in the specific card class, wouldn't that create a circular dependency? So would it be better then to have the hand class figure out what can be done with a specific card and what that specific card effects (which wouldn't that hinder the cohesion of the class?)?
I was also thinking a possible solution might be to have the non-generic card types contain methods that return values as apposed to manipulating higher level classes, such as a boolean drawCards which returns true if cards need to be drawn, false otherwise (same for skip, reverse, exc.).Then maybe the board class can determine what to do if those values are true or false (which actually seems more convoluted since only one value would be allowed to be true at any given time).
The other solution I was considering is to have a single UnoCardRules class, which serves the sole function of providing methods to determine the effects of each card, that way each card class can only worry about defining the card's state.
View Replies
View Related
Jun 11, 2014
Here is the original code I found on StackOverFlow. It highlights some specific words in a JTextPane.
import javax.swing.*;
import java.awt.*;
import javax.swing.text.*;
public class ColorChangeWhileTyping extends JFrame{
private int findLastNonWordChar (String text, int index) {
while (--index >= 0) {
if (String.valueOf(text.charAt(index)).matches("W")) {
[code]....
I dont know for some reason it doesnt work correctly. The colour goes away after I press Space to write the next word.
View Replies
View Related
Mar 25, 2015
I've tried a few different editors, like CKEditor and TinyMCE, but I seem to run into the same problem with every one. The text area seems to be disabled in a modalPanel. Everything looks like it displays properly, but the blinking cursor doesn't show up and you can't enter any text. Below is an example of the a4j:form that I use in the modalPanel with TinyMCE. why I wouldn't be able to enter any text into the editor? Is there a different editor that will work better?
<a4j:form id="commentpanelform">
<htm:table border="0" id="woverify" width="500px">
<htm:tr><htm:td height="20px" valign="top" colspan="2">
<rich:messages styleClass="errorMessage" style="text-align:center;"/>
</htm:td></htm:tr>
[code]....
View Replies
View Related
Jul 29, 2014
Not a Java editor with a GUI, but and editor for editing Java GUI's (Graphically (With JFrame, Swing etc) (Kinda like FrontPage for HTML only for Java/Linux. You just add stuff / drag objects around and then optionally review the code after..
View Replies
View Related
Jul 17, 2014
For some reason when I try to run the program it gives me an "editor does not contain a main type" launch error.
/*
* A program that plays and scores a round of the game Poker Dice. In this game, five dice are rolled. The player is allowed to select a number of those five dice to re-roll. The dice are re-rolled and then scored as if they were a poker hand. The following hands MUST be scored in this assignment:
* * High card
* * One Pair
* * Two Pair
* * Three of a Kind
* * Full House
* * Four of a Kind
* * Five of a Kind
* For extra credit, you may also implement:
* * Straight
*/
import java.util.Scanner;
public class Project10 {
public static void main(String[] args) {
Scanner inScanner = new Scanner(System.in);
int[] dice = new int[5];
resetDice(dice);
System.out.print("Your current dice: + dice");
[code]....
View Replies
View Related
Nov 17, 2014
I am working on a game engine with java. I have come to the final stages of the development of this engine now and need a small hand. For this i am using java's built in libary for graphics. and am strugling to create a nice looking GUi with it, What i need:
The class extends the canvas class and adds it to the jframe, i have set the window up as standard and added a menubar, and net the canvas, what I want to do.
For those of you that have used application such as tiled (shown here [URL] .....) what i am wanting to do is create a gui around the canvas similar to this where the parts on the right are resizable up and down and in and out. i was wondering how i would go about incorporating this.
View Replies
View Related
Jun 27, 2014
I am starting a project of a little game for my brother and I wanted to know whether a few things were possible using Java (I know the basics and am currently learning more, but I have about a year to complete this so I have time to learn what is needed).What I need to be able to do:Be able to view a PDF as well as zoom in and pan around itBe able to enter/edit text in said PDF fileBe able to hide some of the text in this PDFBe able to do this on several PDFs in one program (They won't be open at the same time)
Is it possible to do this in Java? If so, how? (As in, what things would I need to learn or what would I need to complete it)If it makes my question easier, what it will be is a London Underground Tube Map (Which is a PDF file)where some station names disappear and the player has to guess which station(s) are missing.
View Replies
View Related
Mar 19, 2014
I'm want to write a program to design single page documents. It needs the following features.Drag text and place it anywhere on the page, ideal I would like to add a 'snap to grid' optionDraw boxsAdd simple images (logos)
I plan to do it using Swing, but I've not done anything with this since finishing Uni. how to structure this and what swing components will be best suited for this task?
View Replies
View Related
Jun 23, 2014
I'm having a problem with a small text editor I'm trying to create. I have implemented a panel of labels, containing line numbers, on the left of a scrollable text area. The panel is designed to size such that it fits the larger numbers whenever they appear. It does that very well, actually, until either one of the scrollbars appear. As soon as one does appear, it immediately shrinks in width. The horizontal scrollbar even blocks the view a little, making it impossible to see what you are writing on the very last line.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main implements KeyListener {
public static JPanel tab = new JPanel(false);
public static JTextArea text = new JTextArea();
public static JScrollPane scroll, reflex;
public static JPanel lines;
[code]...
Explanation of the code: There is a main panel which embodies a text area and another container filled with labels of line numbers.Both the text area and line number panel have scroll panels attached. They are synchronized, in order to scroll at the same time.
The main class contains a static function "position" which generates a GridBagConstraints, created for the convenience of single-line creation of constraints.It also implements the KeyListener interface, and waits for change in the amount of lines inside the text area. Afterwards, it changes the panel of labels accordingly.
View Replies
View Related
Mar 18, 2015
I am trying to set the font of the editor as the same for the renderer of JTable. I am just a bit confused on how to do this. I don't want any code but maybe a walkthrough on what to do. Here is my abstract table model ....
public class ProductTableModel extends AbstractTableModel {
private ArrayList <Product> prodList = new ArrayList <Product> ();
private String [] columnNames = {"ID", "Description", "Inventory", "Cost", "Order Quantity"};
public ProductTableModel (ArrayList <Product> productList) {
this.prodList = productList;
[Code] .....
View Replies
View Related
Apr 2, 2015
I want to create a jsp where there is a textbox and the user can change font styles (such as bold, italicized, underline, change color, change font style, highlight align a word/s) inside the textbox just like an MS Word. I'm not looking for a system similar to code ranch's posting of message which displays the tag in a textbox...
View Replies
View Related
Jun 16, 2014
I'm using [URL] ....., I'm quite surprise of the fact that there isn't a property for the text value. So you can't bind this component to the model.
Why in our opinion there isn't a property to bind (as in other components)?
View Replies
View Related
Sep 25, 2014
How do I escape the characters of a primefaces editor?
I have this in form in a xhtml page
<p:editor value="#{managebeanX.valor}" />
but when I try to save this value through a sparql query it says:
virtuoso.jdbc4.VirtuosoException: SQ074: Line 2: SP030: SPARQL compiler, line 2: syntax error at 'Apple' before '-'
Here is the sparql query
INSERT INTO GRAPH <http://localhost:8890/Asst> {
<http://www.dominio.edu#Q1> rdf:type asst:Question; asst:prompt "adada <span class="Apple-tab-span" style="white-space:pre"></span>"^^xsd:string. }
The Blue text is the value of the p:editor. It' has html characters... So I think I need to scape those characters... but how?
View Replies
View Related
Jul 23, 2014
What I'm trying to do is make an inventory type program that includes a jtable. In the Jtable in the last column there will be 2 buttons and a textfield to register the value of additions or subtractions to the overal stock amount. (See screenshot in attachment).
As of now I am able to increment or decrement the numbers when the buttons are clicked on however the problem is that if I add 2 to the first row, and then go to add 2 to the next row or any other row for that matter, the value of the previous row is added to the next row, and the previous row reverts back to a value of 0. So basically its like there is only one editor that keeps track of one value no matter what row you are editing.
I need getting it so that I can add different values to each different row depending on the stock being used or received. The following is my code:
Main class
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 155, 643, 233);
IMG.add(scrollPane);
center = new centerJustify();
ts = new tableCellRenderer();
tm = new DefaultTableModel(){
[Code] .....
View Replies
View Related
Mar 22, 2014
The program below compiles and functions correctly for the most part. It is supposed to be a simple GUI Text Editor with Edit and Format functions. The content pane is supposed to be a scroll pane, however no matter how much I type into the editor, the scroll bar does not appear. Also, the none of the functions under the "Edit" menu work.
Java Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
/**
* A simple text editor. It creates and displays the GUI Text Editor.
*/
public class TextEditor extends JFrame implements ActionListener
[Code] .....
View Replies
View Related