| Computing desk | ||
|---|---|---|
| < April 8 | << Mar | April | May >> | April 10 > |
| Welcome to the Wikipedia Computing Reference Desk Archives |
|---|
| The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
(This question continues from here.)
Out of curiosity I tried setting up a Beowulf network using four old personal computers running under Windows XP using Visual Basic as described here.
To my great surprise it works and is fast enough and distributes memory well enough that I am only restricted by subscript out of range, overflow and out of memory errors in only extreme cases.
Is there a way I can improve upon this setup by programming in DOS or in some other way that is relatively user friendly as under Windows XP and Visual Basic 6. --DeeperQA (talk) 09:27, 9 April 2011 (UTC)
I'm trying to create a board game (nine men's morris, if that helps at all). The board is a JPanel with paintComponent overridden to put custom .jpg image (the board image). The playing pieces are a JPanel also with paintComponent overridden to put a custom .png image. What I want to do is when the user clicks on a specific location of the board to put in a piece, the JPanel would be added - or if this is easier, setVisible(true).
Problem is, none worked when I tried one or a combination of these: frame.validate(), board.revalidate() and/or board.repaint() after board.add(piece), or after piece.setVisible(true). I've tried putting in System.out.println("something") after the codes to ensure that the listener is worker fine, and yes it was.
A friend told me to use SwingWorker as a solution, but as an amateur I have no idea how to use it at all even after referring to some links. Any feedback would be appreciated, thanks in advance. — Yurei-eggtart 12:59, 9 April 2011 (UTC)
JPanel piece = new JPanel() {
@Override
public void paintComponent(Graphics g) {
Image img = new ImageIcon("Button"+colour1+".png").getImage();
g.drawImage(img, 0, 0, null);
setBounds(20, 100, img.getWidth(null), img.getHeight(null));
}
};
board.add(piece);
piece.addMouseListener(this);
MAINWINDOW.addMouseListener(this); //MAINWINDOW is the JFrame
basic java example |
|---|
import java.awt.*;
import javax.swing.*;
class Piece extends JComponent {
static final long serialVersionUID = 0x1234L;
private Image myImg;
public Piece(Image i){
myImg = i;
}
public void paintComponent(Graphics g){
g.drawImage(myImg, 0, 0, null);
}
}
class Board extends JPanel {
static final long serialVersionUID = 0x1234L;
public void paintComponent(Graphics g){
g.drawLine(125,0,125,500);
}
}
public class Boardgame {
public static void main(String [] args){
// for this example, white.png and black.png are 50x50
Image whiteimg = new ImageIcon("white.png").getImage();
Image blackimg = new ImageIcon("black.png").getImage();
JFrame frame = new JFrame("hello");
Board board = new Board();
frame.getContentPane().add(board);
board.setLayout(null);
Piece p1 = new Piece(whiteimg);
p1.setBounds(100,100,150,150);
board.add(p1);
Piece p2 = new Piece(blackimg);
p2.setBounds(100,150,150,200);
board.add(p2);
frame.setSize(500,500);
frame.setVisible(true);
}
}
|
if (e.getSource() == board) {
if ((e.getX()<=65&&e.getX()>=20) && (e.getY()<=145&&e.getY()>=100)) {
Piece piece = new Piece(colour1, 20, 100); //a class that extends JPanel that would form the piece
BGPanel.add(piece);
BGPanel.validate();
BG.repaint();
MAINWINDOW.validate();
System.out.println("Hello world");
}
}
Hi:
I have some old books which I want to throw away. But I would also like to keep a digital archive of them. Is there any place in Toronto that does book scanning? Since I plan to throw them away, I don't mind if the scanning shop takes my books and cut away the ridge.
Thanks,
70.29.27.28 (talk) 17:19, 9 April 2011 (UTC)