Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22282
| Date | 2013-02-12 09:47 +0000 |
|---|---|
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
| Organization | Trollbusters 3 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Converting Text File To Rectangles |
| References | <7f49c487-f016-43a3-83a4-feebe072f76c@googlegroups.com> |
| Message-ID | <j62dnbkquNlNkofMnZ2dnUVZ8n2dnZ2d@bt.com> (permalink) |
On 12/02/13 01:51, Scyth3 wrote:
> I have a save and load method for certain rectangles I need for a game. Say the user wants to save a map. The outputted map would look like this:
[snip]
> Now, how would I read this, and turn it into a rectangle?
Off the top of my head, on the way out the door to the swimming pool,
and for multiple rectangles (squares?).
Refactor as required
import java.awt.Graphics;
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.JComponent;
import javax.swing.JFrame;
class MyCanvas extends JComponent {
LinkedList<RectData> data = null;
MyCanvas(LinkedList<RectData> data) {
this.data = data;
}
public void paint(Graphics g) {
Iterator<RectData> iter = data.iterator();
RectData i = null;
while (iter.hasNext()) {
i = iter.next();
g.drawRect(i.x, i.y, i.width, i.height);
}
}
}
class RectData {
Integer x, y, width, height;
RectData(Integer x, Integer y, Integer width, Integer height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
public class DrawRect {
static LinkedList<RectData> getData() {
LinkedList<RectData> data = new LinkedList<RectData>();
data.add(new RectData(50, 250, 50, 50));
data.add(new RectData(50, 350, 50, 50));
data.add(new RectData(50, 400, 50, 50));
data.add(new RectData(50, 500, 50, 50));
data.add(new RectData(150, 300, 50, 50));
data.add(new RectData(200, 450, 50, 50));
data.add(new RectData(200, 500, 50, 50));
data.add(new RectData(250, 150, 50, 50));
data.add(new RectData(300, 100, 50, 50));
data.add(new RectData(400, 50, 50, 50));
data.add(new RectData(450, 150, 50, 50));
data.add(new RectData(550, 100, 50, 50));
return data;
}
public static void main(String[] a) {
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 600, 600);
window.getContentPane().add(new MyCanvas(getData()));
window.setVisible(true);
}
}
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Converting Text File To Rectangles Scyth3 <zfollette@gmail.com> - 2013-02-11 17:51 -0800
Re: Converting Text File To Rectangles Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-02-11 21:02 -0500
Re: Converting Text File To Rectangles Gene Wirchenko <genew@telus.net> - 2013-02-13 09:06 -0800
Re: Converting Text File To Rectangles Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-02-13 13:25 -0500
Re: Converting Text File To Rectangles "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-02-15 15:25 +0000
Re: Converting Text File To Rectangles "John B. Matthews" <nospam@nospam.invalid> - 2013-02-16 13:37 -0500
[OT] Re: Converting Text File To Rectangles Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-02-16 15:16 -0500
Re: [OT] Re: Converting Text File To Rectangles "John B. Matthews" <nospam@nospam.invalid> - 2013-02-17 14:16 -0500
Re: Converting Text File To Rectangles Gene Wirchenko <genew@telus.net> - 2013-02-15 13:09 -0800
Re: Converting Text File To Rectangles Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-12 04:47 -0400
Re: Converting Text File To Rectangles lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-12 12:14 +0000
Re: Converting Text File To Rectangles lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-12 09:47 +0000
Re: Converting Text File To Rectangles lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-02-12 09:50 +0000
Re: Converting Text File To Rectangles Roedy Green <see_website@mindprod.com.invalid> - 2013-02-12 18:23 -0800
Re: Converting Text File To Rectangles Roedy Green <see_website@mindprod.com.invalid> - 2013-02-12 11:41 -0800
csiph-web