public BoardSquare(int p, int q, String type) Your GUI code still needs significant changes, but this will at least let you start seeing what you're dealing with. Now you can see where they are showing up in your GUI. To help visualize what's going on, cause each BoardSquare to be 100x100 pixels in size, and give them a border. Not a good size for something you want to be visible to the user. ![]() You will need to work on setting the correct layout before it will be laid out correctly. Instead, these values should be set to 0,0 because that is the top-left corner of the component you are drawing in.īy just setting the preferred size of the squares and setting x,y to 0, I was able to get the squares drawing in the frame, though it wasn't pretty. But if your x,y are greater than these values, you will be drawing outside of the bounds of the component. Your components (after setting the size) will be 100x100 pixels. This is an offset from the top-left corner of the component. You can do this in the boardSquare constructor: setPreferredSize(new Dimension(100, 100)) įinally, in your drawing code, you are doing an offset of x,y when drawing the squares and circles. You need to tell the squares how big they are. You aren't specifying the size, and so all your squares are 10x10. By default, JPanels have a dimension of 10x10. The bigger problems are in your boardSquare class. You don't have any code to set up the layout, and so your application is using the defaults (FlowLayout is the default, and this may work in your case, as long as your JFrame and children are the appropriate size). Java UI is layout-based, which means that when you add a component to a parent, the parent's layout determines where the child component will be placed. Rectangle box = new Rectangle(x,y,100,100) Public boardSquare(int p, int q, String type) Private int y //y position of the rectangle measured from top left corner Private int x //x position of the rectangle measured from top left corner Private class boardSquare extends JComponent Thanks in advance for any help/suggestionsĮDIT: I should probably alternate drawing blue and gray squares or else the thing will probably just be a giant blue blob, however I'll settle for a giant blue blob at this point :p import javax.swing.* įtDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) I'm also a little uncertain if my circle drawing code will do what I want (ie create solid red or black circles inside certain squares) Here is the code. However all I get when I run the code is a blank frame. The goal of the code at this point is to draw the initial board (red pieces at top, black at bottom). However it's been a long time since I've used the java GUI tools. Life-like cellular automata (incl.I'm begining a little project to create a simple checkers game.Buckblog maze generation algorithm overview.Find combinations of a string in another string.That's why I'm thinking a transposition table may help. Wikipedia says these are all NP, but efficiency can be improved by dynamic programming. The "correct change" problem looks like it's equivalent to the "subset sum" problem, which is a special case of the knapsack problem.Box stacking problem (and other DP problems).Maximum subarray problem (Kadane's algorithm). ![]() Sliding puzzle solving with hill climbing.Working out the initial probabilities for the stochastic matrix requires only basic probability, but it's tricky. Worth solving using both simulation (I used first-class functions) and stochastic matrix (I used numpy). #93 Sudoku can also be solved using Integer Linear Programming.Christopher Alexander's Design Patterns.Gene Cooperman's Computer Science Information.
0 Comments
Leave a Reply. |