Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!

malcolm bailey

Greenhorn
+ Follow
since Aug 10, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by malcolm bailey

.. still not working... I have no idea why. My subclass of JPanel has BoxLayout as it�s layout, I don�t know if this helps. Is there anything I should specify, or not specify in terms of layout, size... anything??
17 years ago
Hi Nate,
Unfortunately, I�m really using JPanel. I�m going to check through the code again, see what I can find...
17 years ago
Hi Folks,
I have an application that is, at the moment, a GUI frame with a JToolBar at the top and, below it, a JTabbedPane with a JScrollPane inside it. The JScrollPane has a JPanel which contains various text areas (more than can fit on the screen). My problem is, that when I scroll downwards, the content of the panel moves upwards, as expected, but it covers the tabbedPane and the toolBar as well!! How do I prevent this from happening?? Also, I�m using
this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
to operate in "full screen" mode, but the bottom of the GUI is covered by the Windows start bar thingy that goes along the bottom of the screen.
Here�s some code...
JToolBar toolbar = new JToolBar();
//add buttons to toolBar..
JTabbedPane tabbedPane = new JTabbedPane();
JScrollPane sp = new JScrollPane();
//myPanel is an instance of a class that extends JPanel
sp.getViewport().add( myPanel );
tabbedPane.addTab( nameOfTab, sp );
this.getContentPane().add(toolbar, BorderLayout.NORTH);
this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
I�ve got lots of other stuff going on, adding buttons and listeners, but this is the part that applies to the tab. I�ll post more detail if necesary.
Thanks very much to all who can help!
Malc.
17 years ago
Hi All,
Thanks for the contributions, I have a result, but only when I use the absolute path, which I should really avoid. I changed the file extension to .jpg - cheers, Greg...
JBuilder Properites:
My source path is:
C:/Malcolm/myprojects
My output path is:
C:/Malcolm/myclasses
My absolute path:
"C:/Malcolm/myclasses/ficha/save.jpg"
Any further pointers? (We�re almost there!!!)
Malc
17 years ago
Hi Michael,
I think I may have missed something pretty basic. I moved my images folder to the same directory as my classes, but it still didn�t work. I created everything in JBuilder, which sometimes moves things about when you compile. I have a folder called "Malcolm/myprojecs/ficha", in which I have the .jpr file and MainFrame.java. Jbuilder created "Malcolm/myclasses/ficha", so I put "images" into the "ficha" folder, but no joy..
I must be organising things badly.. How should it all be arranged?
Malc
17 years ago
Hello all,
Can anyone tell me why the image I have does not appear on the JButton? I can�t see why, I{ve tried using the absolute path, but to no avail. Here�s the code (I�ve started, and I�m just experimenting at the moment.. )
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
public class MainFrame extends JFrame {
JToolBar toolbar = new JToolBar();
XYLayout xYLayout1 = new XYLayout();
JButton button;
JButton button2;
JButton button3;
JButton button4;
TitledBorder titledBorder1;

public MainFrame() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
titledBorder1 = new TitledBorder("Ficha");
toolbar.setForeground(new java.awt.Color(77, 77, 108));
toolbar.setBorder(BorderFactory.createEtchedBorder());
toolbar.setSize(600, 50);
button = new JButton(new ImageIcon("images/save.jpeg"));
button2 = new JButton("blah");
button3 = new JButton("blah");
button4 = new JButton("blah");
toolbar.add(button);
toolbar.add(button2);
toolbar.add(button3);
toolbar.add(button4);
this.getContentPane().setLayout(xYLayout1);
this.getContentPane().add(toolbar, new XYConstraints(0, 0, 600, 30));
this.setSize(600, 450);
this.show();
}
public static void main(String args[]) {
MainFrame mainf = new MainFrame();
}
}
Thanks very much...
Malc
17 years ago
.. I reckon it might work if I can manipulate piece in it�s own separate Graphics conext. Is this a good idea, and does anyone know how I could do this? I tried a this:
piece.move(piece.getGraphics)
in the board�s paintComponet(), but it didn�t work (I got a null pointer exception).
17 years ago
oh, and I tried putting
super.paintComponents(g);
in as well...
17 years ago
Hi All,
I have a program where I have various Displays added to a JFrame. If I run this:
package tetris_1_1;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Display extends JPanel
{
protected Dimension d;
protected int width, height;
public Display()
{
}
public Display(int width, int height, String title)
{
d = new Dimension(width, height);
setBackground(Color.black);
if(title != null)
{
this.setBorder(new TitledBorder(null, title, TitledBorder.RIGHT, TitledBorder.BOTTOM));
}
}
public void drawGrid(Graphics g)
{
g.setColor(Color.white);
for(int i=0; i<width; i+=20)
{
g.drawLine(i, 0, i, height);
}
for(int j=0; j<width; j+=20)
{
g.drawLine(0, j, width, j);
}
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
public Dimension getPreferredSize()
{
return new Dimension(d);
}
}
with a call from the JFrame like:
scoreboard = new Display(100, 50, "score");
.
.
c.add(scoreboard);//(Container c = getContentPane(); )
it works fine, but if I want to call drawGrid(); to draw a grid in the Display, it messes up. I override paintComponent(), but when it runs, the Displays disappear. This is my paintComponent():
paintComponent(Graphics g)
{
drawGrid(g);
}
I've tried modifying it thus:
paintComponent(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
drawGrid(g);
}
but that doesn't work either.
Any ideas folks?
Malc.
17 years ago
Hi Rene,
Thanks for the posting, but it doesn�t seem to work with what I�m trying to do. The container I�m adding the piece to is the "board" for the game, which contains other graphics, so I don�t want to have to repaint() every time I move a piece. I have a slightly different version which I've decided to do where I create a piece in the in my Game class:
piece Piece = new Piece(chooseColor(), choosePolygon);
..then I add the piece to the Board and then call piece.move() when the user pushes a particular key. I also have an infinite loop in Game's run() method that calls piece.move() every second. As I said before, I'm trying to move it with translate{}. The really annoying thing is, I had another version of this program which I started ages ago but never completed. At first, I had the same problem, but I can't remember how I got round it!! Maybe I'm using the wrong approach..
17 years ago
Hello all,
I hope someone out there can give me a hand with this... I�m writing a game where I want to move a piece to a different position on the screen at the user�s input. My Piece object, which extends JPanel, has the following method:
public void movePiece(Graphics g)
{
erasePiece(g);
g.translate(0, 20);
g.setColor(color);
g.fillPolygon(poly);
}
This works Ok the first time I use it; the piece "disappears" and is redrawn according to g.transform, and it look as if it has moved, which is what I want. The problem is that it doesn't work on subsequent calls. Instead of translate() moving the piece from the new position, it appears to use the origal origin.
Please help me!! What am I doing wrong? Here's the main stuff from the Piece class..
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Piece extends JPanel
{
private Polygon poly;
private Color color;
private Vector colors, yellow, green, blue, purple, red, pieces;
public Piece()//Polygon p, Color c)
{
colors = new Vector();
yellow = new Vector();
green = new Vector();
blue = new Vector();
purple = new Vector();
red = new Vector();
pieces = new Vector();
setPieces();
setColors();
poly = choosePiece();
color = chooseColor();
}
public void paintComponent(Graphics g)
{
g.setColor(color);
g.fillPolygon(poly);
}
public Polygon getPolygon()
{
return poly;
}
public Color getColor()
{
return color;
}
public void movePiece(Graphics g)
{
erasePiece(g);
g.translate(0, 20);
g.setColor(color);
g.fillPolygon(poly);
}
public void erasePiece(Graphics g)
{
g.setColor(Color.black);
g.fillPolygon(poly);
}
public void setPieces()
{
//puts polygons in the pieces vector
}
public void setColors()
{
//puts colors in the colors vector
}
public Polygon choosePiece()
{
//chooses a piece at random from the vector of pieces
}
public Color chooseColor()
{
//chooses a color at random from the vector of colors
}


}
17 years ago
Hi Nate,
SOrry I've not replied, I've been away from programming for a wee while, but I've had a look at what you suggested and it's working well, thanks very much!!
Malc
18 years ago
Hello People,
I'm trying to write a game that invloves placing a piece on a "board" and then doing stuff to it, like moving it about etc.. I would like to have a grahic that is independent of the board, but I don't know how to do this. At the moment, I have a piece that I place on the board, but I've done it with a polygon, which is part of the board, by definition. My code looks something like this (off the top of my head..)
public class board extends JPanel
{
public board()
{
//constructor stuff..
}
public void paintComponent(Graphics g)
{
g.setColor(Color.black);
g.fillRect(200,400);

int [] x = {x1, x2, x3, x4}
int [] y = {y1, y2, y3, y4}
Polygon p = new Polygon(x, y, 4);
g.setColor(Color.white);
g.fillPolygon(p);
}
//more code that does other stuff..
}
I basically want something that I can place anywhere I like, and then move or rotate it, etc.. I reckon it would be better to have something independent of the JPanel so I could then put it in a different class and manipulate it independently if I want to.
Any help would, of course, be greatly appreciated!
Cheers,
Malcolm
18 years ago
Thanks Peter, I'll see what I can do...
..I'm not sure how to do it, though, as I'm fairly new to this..