Adding a timer between animations in Java - java

Hi guys so I got this issue of adding a timer between the animations, the issue with my code is that the last animation must wait a sufficient time, in order to let the previous animations to end, the code is
if (array1[0]>array1[1])
{
AnimationClass a = new AnimationClass();
a.jButtonYUp(110, 30, 100,1, jButton6);
a.jButtonXLeft(250, 50, 100, 1, jButton6);
a.jButtonXRight(50, 250, 100, 1, jButton5);
// I need the timer here about 2 seconds
a.jButtonYDown(30, 110, 100, 1, jButton2);
}
So I would greatly appreciate if somebody could direct me to the question if its already there or answer this for me
BTW that AnimationClass is a library developed by a you-tuber and I am currently following his tutorials

if (array1[0]>array1[1])
{
AnimationClass a = new AnimationClass();
a.jButtonYUp(110, 30, 100,1, jButton6);
a.jButtonXLeft(250, 50, 100, 1, jButton6);
a.jButtonXRight(50, 250, 100, 1, jButton5);
Timer timer1 = new Timer();
MyTimerTask timer1_task = new MyTimerTask();
timer1.schedule (timer1_task, 2000, 0);
}
class MyTimerTask extends TimerTask
{
public void run()
{
a.jButtonYDown(30, 110, 100, 1, jButton2);
}
}

Related

Adding textures effectively in 3D game using libGDX

I'm writing a 3D game in Java using libGDX. In my game there's a model instance of a room which his walls are just rectangles. I'm tryimg to add an effect of "bullet holes" which are just a texture that appear on the wall when the player shoots at it. I'm trying to figure what the optimal way to implement it? The obvious way is just creating a model instance that built from a single rect with the hole texture for each bullet hole - but this way there will be a draw call for each one of these holes, which is not performance-wise AFAIK.
A piece of code which I create the walls:
Texture wallTexture = new Texture(Gdx.files.internal("wall.png"));
wallTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
Material wallMaterial = new Material(TextureAttribute.createDiffuse(wallTexture));
MeshPartBuilder meshBuilder = modelBuilder.part("walls", GL20.GL_TRIANGLES,
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal |
VertexAttributes.Usage.TextureCoordinates, wallMaterial);
meshBuilder.setUVRange(0, 0, C.ROOM_SIZE, 3);
corner00.set(C.ROOM_SIZE, 0, 0);
corner10.set(0, 0, 0);
corner11.set(0, 0, 6);
corner01.set(C.ROOM_SIZE, 0, 6);
normal.set(0, 1, 0);
line1000.setNormalDirection(auxVector2.set(0, 1).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(C.ROOM_SIZE, C.ROOM_SIZE, 0);
corner10.set(C.ROOM_SIZE, 0, 0);
corner11.set(C.ROOM_SIZE, 0, 6);
corner01.set(C.ROOM_SIZE, C.ROOM_SIZE, 6);
normal.set(-1, 0, 0);
line1110.setNormalDirection(auxVector2.set(-1, 0).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(0, C.ROOM_SIZE, 0);
corner10.set(C.ROOM_SIZE, C.ROOM_SIZE, 0);
corner11.set(C.ROOM_SIZE, C.ROOM_SIZE, 6);
corner01.set(0, C.ROOM_SIZE, 6);
normal.set(0, -1, 0);
line0111.setNormalDirection(auxVector2.set(0, -1).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
corner00.set(0, 0, 0);
corner10.set(0, C.ROOM_SIZE, 0);
corner11.set(0, C.ROOM_SIZE, 6);
corner01.set(0, 0, 6);
normal.set(1, 0, 0);
line0001.setNormalDirection(auxVector2.set(1, 0).angle());
meshBuilder.rect(corner00, corner10, corner11, corner01, normal);
Model levelModel = modelBuilder.end();
levelModelInstance = new ModelInstance(levelModel);
This part occurs only once upon loading the level. The bullet holes are supposed to appear in-game.

Apache POI XSLFAutoShape - Shape OffSet property

I am drawing a pptx from scratch using ApachePOI-XSLF (ooxml implementation) and I am struggling to find good documentation and good examples. Also the library isn't easy to follow and not straight forward.
I would like to know how do I set the offset of two shapes of XSFLAutoShape connected by XSLFConnectorShape.
This is my code right now:
XMLSlideShow pptx = new XMLSlideShow();
XSLFSlide slide = pptx.createSlide();
XSLFAutoShape rectangle = slide.createAutoShape();
rectangle.setShapeType(ShapeType.RECT);
rectangle.setAnchor(new Rectangle2D.Double(100, 100, 100, 50));
rectangle.setLineColor(Color.blue);
rectangle.setFillColor(Color.lightGray);
XSLFAutoShape miniCircle = slide.createAutoShape();
miniCircle.setShapeType(ShapeType.ELLIPSE);
miniCircle.setAnchor(new Rectangle2D.Double(rectangle.getAnchor().getMaxX() + 200, rectangle.getAnchor().getCenterY()+50, 1, 1));
miniCircle.setLineColor(Color.yellow);
miniCircle.setFillColor(Color.yellow);
connect(slide, rectangle, miniCircle);
XSLFAutoShape anotherRectangle = slide.createAutoShape();
anotherRectangle.setShapeType(ShapeType.RECT);
anotherRectangle.setAnchor(new Rectangle2D.Double(miniCircle.getAnchor().getMaxX() + 200, 100, 100, 50));
anotherRectangle.setLineColor(Color.blue);
anotherRectangle.setFillColor(Color.lightGray);
connect(slide, miniCircle, anotherRectangle);
and the connect method:
public static void connect(XSLFSlide slide, XSLFAutoShape start, XSLFAutoShape end){
XSLFConnectorShape connector = slide.createConnector();
connector.setAnchor(new Rectangle2D.Double(start.getAnchor().getX() + 100, start.getAnchor().getCenterY(), 100, 1));
CTConnector ctConnector = (CTConnector)connector.getXmlObject();
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
// connection start
CTConnection stCxn = cx.addNewStCxn();
stCxn.setId(start.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
stCxn.setIdx(3);
CTConnection endCxn = cx.addNewEndCxn();
endCxn.setId(end.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
endCxn.setIdx(3);
}
The output of is:
This is the output
But I want this:
This is what I want
p.s. I edit the post because someone thumbs down the post without a reason. I added more info but still complicated because the library is complicated :-/. would mind help and thumbs up again ? If you cannot help at least do not destroy my reputation. I am serious developer. Tkx.

Threads constantly interrupting each other, log doesn't reflect system operations

I built a system that simulates memory paging, just like an MMU.
And to better regulate and understand how it works, I am logging it.
My problem is that it seems the log is not accurately reflecting the operations of the system, or rather it does, but then I have a big problem with threads that I need some help solving.
I'll try and explain.
public void run() //gets pages and writes to them
{ // i printed the pageId of every process to check they are running at the same time and competing for resources
for(ProcessCycle currentCycle : processCycles.getProcessCycles())
{
Long[] longArray = new Long[currentCycle.getPages().size()];
try {
for(int i = 0; i < currentCycle.getPages().size();i++)
{
MMULogger.getInstance().write("GP:P" + id + " " + currentCycle.getPages().get(i) + " " + Arrays.toString(currentCycle.getData().get(i)), Level.INFO);
}
Page<byte[]>[] newPages = mmu.getPages(currentCycle.getPages().toArray(longArray));
List<byte[]> currentPageData = currentCycle.getData();
System.out.println("process id " + id);
for(int i = 0; i < newPages.length;i++)
{
byte[] currentData = currentPageData.get(i);
newPages[i].setContent(currentData);
}
Thread.sleep(currentCycle.getSleepMs());
} catch (ClassNotFoundException | IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
this code snippet is taken from a class called Process. Just like in a computer, I have multiple processes, and they each need to read and write from pages, which they request from the class called MMU. this is the "mmu.getpages" part.
We also write to our log file inside the method get pages:
public synchronized Page<byte[]>[] getPages(java.lang.Long[] pageIds) throws java.io.IOException, ClassNotFoundException
{
#SuppressWarnings("unchecked")
Page<byte[]>[] toReturn = new Page[pageIds.length];
for(int i = 0; i < pageIds.length; i++)
{
Long currentPage = algo.getElement(pageIds[i]);
if(currentPage == null) //page not found in RAM
{
if(ram.getInitialCapacity() != ram.getNumOfPages()) //ram is NOT full
{
MMULogger.getInstance().write("PF:"+pageIds[i], Level.INFO);
algo.putElement(Long.valueOf(pageIds[i]),Long.valueOf(pageIds[i]));
ram.addPage(HardDisk.getInstance().pageFault(pageIds[i]));
}
else //ram is full
{
Long IDOfMoveToHdPage = algo.putElement(pageIds[i], pageIds[i]);
Page<byte[]> moveToHdPage = ram.getPage((int)((long)IDOfMoveToHdPage));
Page<byte[]> moveToRAM = HardDisk.getInstance().pageReplacement(moveToHdPage, pageIds[i]);
ram.removePage(moveToHdPage);
ram.addPage(moveToRAM);
MMULogger.getInstance().write("PR: MTH " + moveToHdPage.getPageId() + " MTR " + moveToRAM.getPageId(), Level.INFO);
}
}
toReturn[i] = ram.getPage((int)((long)pageIds[i]));
}
return toReturn;
}
So all in all to recap - a process requests pages, I write to the log file which process requests which page and what it wants to write to it, and then I call mmu.getpages, and the logic of the system continues.
My problem is that the log looks like this:
GP:P2 5 [102, 87, -9, 85, -5]
GP:P1 1 [-9, -18, 50, -124, -102]
GP:P4 10 [79, -51, 67, 118, 111]
GP:P2 6 [-20, -22, 3, -74, -65]
GP:P3 7 [90, 56, 91, 71, -115]
PF:5
GP:P6 18 [28, -39, -3, 64, -117]
GP:P5 13 [72, -26, 52, -84, 6]
GP:P4 11 [-55, -70, -88, -9, 38]
GP:P1 2 [39, 112, -117, 5, 109]
GP:P5 12 [38, -31, 18, -40, 36]
which is not what I wanted. At first you can see process 2 requested page 5 and wanted to write to it [102, 87, -9, 85, -5].
After that line, I would have expected to see "PF:5" but its further down. I think it is the case because process 2 ran out of time and didnt manage to finish mmu.getpages operation. so it never printed PF:5 to the file.
That is a problem for me. I want the processes to run simultaneously in a multithreaded fashion, but i want the log to be of the form:
GP:P2 5 [1,1,1,1,1]
PF:5
GP:P2 7 [1,2,3,4,5]
PF:7
GP:P19 12 [0,0,0,0,0]
PF:12
For example

Java SWT ScrolledForm Background Color

I am having an issue with a ScrolledForm. I am trying to change the background and foreground colour for a Label defined in the body of the ScrolledForm, however it doesn't seem to be working.
In my code snippet, I would like lblWhat to have a black background and white foreground.
Here is my code snippet:
ScrolledForm scrldfrmNewScrolledform = formToolkit.createScrolledForm(parent);
scrldfrmNewScrolledform.setLayoutData(gd);
scrldfrmNewScrolledform.setFont(SWTResourceManager.getFont("Segoe UI", 16, SWT.NORMAL));
scrldfrmNewScrolledform.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
scrldfrmNewScrolledform.getBody().setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
scrldfrmNewScrolledform.setImage(SWTResourceManager.getImage(EPRForm.class, "/icons/AFCCEPR.png"));
scrldfrmNewScrolledform.setBounds(10, 10, 430, 280);
formToolkit.paintBordersFor(scrldfrmNewScrolledform);
scrldfrmNewScrolledform.setText("ePR (electronic Purchase Request)");
Label lblName = new Label(scrldfrmNewScrolledform.getBody(), SWT.NONE);
lblName.setBounds(10, 21, 55, 15);
formToolkit.adapt(lblName, true, true);
lblName.setText("Name:");
text = new Text(scrldfrmNewScrolledform.getBody(), SWT.BORDER);
text.setBounds(71, 15, 269, 21);
formToolkit.adapt(text, true, true);
Label lblWhat = new Label(scrldfrmNewScrolledform.getBody(), SWT.None);
lblWhat.setBounds(10, 35, 100, 15);
lblWhat.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
lblWhat.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
formToolkit.adapt(lblWhat, true, true);
lblWhat.setText("What do you want?");
Label lblItem = new Label(scrldfrmNewScrolledform.getBody(), SWT.None);
lblItem.setBounds(10, 55, 100, 15);
formToolkit.adapt(lblItem, true, true);
lblItem.setText("Items to be Ordered*");
txtItems = new Text(scrldfrmNewScrolledform.getBody(), SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
txtItems.setBounds(10, 60, 338, 84);
formToolkit.adapt(txtItems, true, true);
You seem to be using FormToolkit. The FormToolkit.adapt method forces the control colors to the colors set for the form (normally white background and black text).
For a single control you could try calling setBackground and setForeground after the adapt call.
You can set the colors for the entire form with
FormColors colors = toolkit.getColors();
colors.setBackground(...);
colors.setForeground(...);

Java Graphics2D Path2D Simplify or call from separate class

I'm wondering if I can clean up my code somehow using a list or call it from another class because I have a lot of exact Path2D coordinates just cluttering my paintComponent.
public void paintComponent(Graphics g)
{ Graphics2D g2=(Graphics2D)g;
super.paintComponent(g2);
//Background
Rectangle background = new Rectangle(0,0,getWidth(),getHeight());
Color skyBlue = new Color(135,206,235);
g2.setColor(skyBlue);
g2.fill (background);
Path2D bunny = new Path2D.Float();
bunny.moveTo(486.63,530.25);
bunny.lineTo(483.13,532.25);
bunny.lineTo(483.13,532.25);
bunny.lineTo(483.13,532.25);
bunny.lineTo(477.38,534.38);
bunny.lineTo(477.38,534.38);
bunny.lineTo(477.38,534.38);
bunny.lineTo(469.88,535.50);
bunny.lineTo(469.88,535.50);
bunny.lineTo(469.88,535.50);
bunny.lineTo(453.50,536.38);
bunny.lineTo(453.50,536.38);
bunny.lineTo(453.50,536.38);
bunny.lineTo(437.63,537.75);
bunny.lineTo(437.63,537.75);
bunny.lineTo(437.63,537.75);
bunny.lineTo(418.75,539.25);
bunny.lineTo(418.75,539.25);
bunny.lineTo(418.75,539.25);
bunny.lineTo(405.00,539.88);
bunny.lineTo(405.00,539.88);
bunny.lineTo(405.00,539.88);
bunny.lineTo(392.25,539.63);
bunny.lineTo(392.25,539.63);
bunny.lineTo(392.25,539.63);
bunny.lineTo(385.50,539.13);
bunny.lineTo(385.50,539.13);
bunny.lineTo(385.50,539.13);
bunny.lineTo(381.00,538.63);
bunny.lineTo(381.00,538.63);
bunny.lineTo(381.00,538.63);
bunny.lineTo(375.50,537.88);
bunny.lineTo(375.50,537.88);
bunny.lineTo(375.50,537.88);
bunny.lineTo(370.13,537.75);
bunny.lineTo(370.13,537.75);
bunny.lineTo(370.13,537.75);
bunny.lineTo(364.88,537.13);
bunny.lineTo(364.88,537.13);
bunny.lineTo(364.88,537.13);
bunny.lineTo(357.75,536.63);
bunny.lineTo(357.75,536.63);
bunny.lineTo(357.75,536.63);
bunny.lineTo(353.50,536.25);
bunny.lineTo(353.50,536.25);
bunny.lineTo(353.50,536.25);
bunny.lineTo(347.88,535.75);
bunny.lineTo(347.88,535.75);
bunny.lineTo(347.88,535.75);
bunny.lineTo(341.75,535.38);
bunny.lineTo(341.75,535.38);
bunny.lineTo(341.75,535.38);
bunny.lineTo(336.25,534.38);
bunny.lineTo(336.25,534.38);
bunny.lineTo(336.25,534.38);
bunny.lineTo(328.25,532.88);
bunny.lineTo(328.25,532.88);
bunny.lineTo(328.25,532.88);
bunny.lineTo(323.00,530.63);
bunny.lineTo(323.00,530.63);
bunny.lineTo(323.00,530.63);
bunny.lineTo(318.50,528.13);
bunny.lineTo(318.50,528.13);
bunny.lineTo(318.50,528.13);
bunny.lineTo(313.50,524.63);
bunny.lineTo(313.50,524.63);
bunny.lineTo(313.50,524.63);
bunny.lineTo(311.63,521.25);
bunny.lineTo(311.63,521.25);
bunny.lineTo(311.63,521.25);
bunny.lineTo(310.38,516.25);
bunny.lineTo(310.38,516.25);
bunny.lineTo(310.38,516.25);
bunny.lineTo(309.88,513.00);
bunny.lineTo(309.88,513.00);
bunny.lineTo(309.88,513.00);
bunny.lineTo(311.13,508.38);
bunny.lineTo(311.13,508.38);
bunny.lineTo(311.13,508.38);
bunny.lineTo(312.25,505.38);
bunny.lineTo(312.25,505.38);
bunny.lineTo(312.25,505.38);
bunny.lineTo(313.00,502.63);
bunny.lineTo(313.00,502.63);
bunny.lineTo(313.00,502.63);
bunny.lineTo(314.75,500.00);
bunny.lineTo(314.75,500.00);
bunny.lineTo(314.75,500.00);
bunny.lineTo(316.38,497.63);
bunny.lineTo(316.38,497.63);
bunny.lineTo(316.38,497.63);
bunny.lineTo(316.25,494.00);
bunny.lineTo(316.25,494.00);
bunny.lineTo(316.25,494.00);
bunny.lineTo(314.88,491.00);
bunny.lineTo(314.88,491.00);
bunny.lineTo(314.88,491.00);
bunny.lineTo(312.88,486.38);
bunny.lineTo(312.88,486.38);
bunny.lineTo(312.88,486.38);
bunny.lineTo(310.13,480.00);
bunny.lineTo(310.13,480.00);
bunny.lineTo(310.13,480.00);
bunny.lineTo(308.50,474.75);
bunny.lineTo(308.50,474.75);
bunny.lineTo(308.50,474.75);
bunny.lineTo(306.63,468.75);
bunny.lineTo(306.63,468.75);
bunny.lineTo(306.63,468.75);
bunny.lineTo(305.25,462.75);
bunny.lineTo(305.25,462.75);
bunny.lineTo(305.25,462.75);
bunny.lineTo(304.88,456.63);
bunny.lineTo(304.88,456.63);
bunny.lineTo(304.88,456.63);
bunny.lineTo(304.88,449.88);
bunny.lineTo(304.88,449.88);
bunny.lineTo(304.88,449.88);
bunny.lineTo(305.00,446.38);
bunny.lineTo(305.00,446.38);
bunny.lineTo(305.00,446.38);
bunny.lineTo(305.88,442.75);
bunny.lineTo(305.88,442.75);
bunny.lineTo(305.88,442.75);
bunny.lineTo(307.63,437.88);
bunny.lineTo(307.63,437.88);
bunny.lineTo(307.63,437.88);
bunny.lineTo(309.25,434.50);
bunny.lineTo(309.25,434.50);
bunny.lineTo(309.25,434.50);
bunny.lineTo(310.50,432.25);
bunny.lineTo(310.50,432.25);
bunny.lineTo(310.50,432.25);
bunny.lineTo(311.63,430.25);
bunny.lineTo(311.63,430.25);
bunny.lineTo(311.63,430.25);
bunny.lineTo(312.50,427.25);
bunny.lineTo(312.50,427.25);
bunny.lineTo(312.50,427.25);
bunny.lineTo(312.63,424.00);
bunny.lineTo(312.63,424.00);
bunny.lineTo(312.63,424.00);
bunny.lineTo(311.75,421.25);
bunny.lineTo(311.75,421.25);
bunny.lineTo(311.75,421.25);
bunny.lineTo(309.38,417.88);
bunny.lineTo(309.38,417.88);
bunny.lineTo(309.38,417.88);
bunny.lineTo(307.00,415.00);
bunny.lineTo(307.00,415.00);
bunny.lineTo(307.00,415.00);
bunny.lineTo(304.50,412.25);
bunny.lineTo(304.50,412.25);
bunny.lineTo(304.50,412.25);
bunny.lineTo(302.63,409.38);
bunny.lineTo(302.63,409.38);
bunny.lineTo(302.63,409.38);
bunny.lineTo(300.13,406.63);
bunny.lineTo(300.13,406.63);
bunny.lineTo(300.13,406.63);
bunny.lineTo(298.00,402.88);
bunny.lineTo(298.00,402.88);
bunny.lineTo(298.00,402.88);
bunny.lineTo(296.63,400.50);
bunny.lineTo(296.63,400.50);
bunny.lineTo(296.63,400.50);
bunny.lineTo(295.38,397.88);
bunny.lineTo(295.38,397.88);
bunny.lineTo(295.38,397.88);
bunny.lineTo(294.50,395.63);
bunny.lineTo(294.50,395.63);
bunny.lineTo(294.50,395.63);
bunny.lineTo(294.13,392.88);
bunny.lineTo(294.13,392.88);
bunny.lineTo(294.13,392.88);
bunny.lineTo(293.13,389.88);
bunny.lineTo(293.13,389.88);
bunny.lineTo(293.13,389.88);
bunny.lineTo(292.38,385.75);
bunny.lineTo(292.38,385.75);
bunny.lineTo(292.38,385.75);
bunny.lineTo(291.75,381.13);
bunny.lineTo(291.75,381.13);
bunny.lineTo(291.75,381.13);
bunny.lineTo(290.88,371.75);
bunny.lineTo(290.88,371.75);
bunny.lineTo(290.88,371.75);
bunny.lineTo(291.13,366.88);
bunny.lineTo(291.13,366.88);
bunny.lineTo(291.13,366.88);
bunny.lineTo(293.25,362.50);
bunny.lineTo(293.25,362.50);
bunny.lineTo(293.25,362.50);
bunny.lineTo(295.38,358.88);
bunny.lineTo(295.38,358.88);
bunny.lineTo(295.38,358.88);
bunny.lineTo(296.75,356.38);
bunny.lineTo(296.75,356.38);
bunny.lineTo(296.75,356.38);
bunny.lineTo(300.00,350.00);
bunny.lineTo(300.00,350.00);
bunny.lineTo(300.00,350.00);
bunny.lineTo(305.63,342.75);
bunny.lineTo(305.63,342.75);
bunny.lineTo(305.63,342.75);
bunny.lineTo(309.88,337.00);
bunny.lineTo(309.88,337.00);
bunny.lineTo(309.88,337.00);
bunny.lineTo(313.50,333.13);
bunny.lineTo(313.50,333.13);
bunny.lineTo(313.50,333.13);
bunny.lineTo(319.25,327.63);
bunny.lineTo(319.25,327.63);
bunny.lineTo(319.25,327.63);
bunny.lineTo(323.38,324.00);
bunny.lineTo(323.38,324.00);
bunny.lineTo(323.38,324.00);
bunny.lineTo(328.38,321.25);
bunny.lineTo(328.38,321.25);
bunny.lineTo(328.38,321.25);
bunny.lineTo(333.75,318.88);
bunny.lineTo(333.75,318.88);
bunny.lineTo(333.75,318.88);
bunny.lineTo(338.50,316.38);
bunny.lineTo(338.50,316.38);
bunny.lineTo(338.50,316.38);
bunny.lineTo(341.63,315.50);
bunny.lineTo(341.63,315.50);
bunny.lineTo(341.63,315.50);
bunny.lineTo(348.50,313.25);
bunny.lineTo(348.50,313.25);
bunny.lineTo(348.50,313.25);
bunny.lineTo(355.25,312.00);
bunny.lineTo(355.25,312.00);
bunny.lineTo(355.25,312.00);
bunny.lineTo(361.00,310.88);
bunny.lineTo(361.00,310.88);
bunny.lineTo(361.00,310.88);
bunny.lineTo(364.50,309.75);
bunny.lineTo(364.50,309.75);
bunny.lineTo(364.50,309.75);
bunny.lineTo(367.75,307.50);
bunny.lineTo(367.75,307.50);
bunny.lineTo(367.75,307.50);
bunny.lineTo(373.25,302.50);
bunny.lineTo(373.25,302.50);
bunny.lineTo(373.25,302.50);
bunny.lineTo(379.13,296.13);
bunny.lineTo(379.13,296.13);
bunny.lineTo(379.13,296.13);
bunny.lineTo(384.25,290.13);
bunny.lineTo(384.25,290.13);
bunny.lineTo(384.25,290.13);
bunny.lineTo(389.25,283.88);
bunny.lineTo(389.25,283.88);
bunny.lineTo(389.25,283.88);
bunny.lineTo(393.25,279.50);
bunny.lineTo(393.25,279.50);
bunny.lineTo(393.25,279.50);
bunny.lineTo(396.63,275.50);
bunny.lineTo(396.63,275.50);
bunny.lineTo(396.63,275.50);
bunny.lineTo(400.50,271.38);
bunny.lineTo(400.50,271.38);
bunny.lineTo(400.50,271.38);
bunny.lineTo(406.25,266.75);
bunny.lineTo(406.25,266.75);
bunny.lineTo(406.25,266.75);
bunny.lineTo(411.50,262.13);
bunny.lineTo(411.50,262.13);
bunny.lineTo(411.50,262.13);
bunny.lineTo(414.88,259.75);
bunny.lineTo(414.88,259.75);
bunny.lineTo(414.88,259.75);
bunny.lineTo(420.25,256.63);
bunny.lineTo(420.25,256.63);
bunny.lineTo(420.25,256.63);
bunny.lineTo(424.63,253.88);
bunny.lineTo(424.63,253.88);
bunny.lineTo(424.63,253.88);
bunny.lineTo(427.50,252.88);
bunny.lineTo(427.50,252.88);
bunny.lineTo(427.50,252.88);
bunny.lineTo(431.13,251.50);
bunny.lineTo(431.13,251.50);
bunny.lineTo(431.13,251.50);
bunny.lineTo(434.25,251.13);
bunny.lineTo(434.25,251.13);
bunny.lineTo(434.25,251.13);
bunny.lineTo(437.63,251.00);
bunny.lineTo(437.63,251.00);
bunny.lineTo(437.63,251.00);
bunny.lineTo(442.50,252.25);
bunny.lineTo(442.50,252.25);
bunny.lineTo(442.50,252.25);
bunny.lineTo(445.50,253.75);
bunny.lineTo(445.50,253.75);
bunny.lineTo(445.50,253.75);
bunny.lineTo(447.88,255.25);
bunny.lineTo(447.88,255.25);
bunny.lineTo(447.88,255.25);
bunny.lineTo(450.50,258.25);
bunny.lineTo(450.50,258.25);
bunny.lineTo(450.50,258.25);
bunny.lineTo(451.88,260.75);
bunny.lineTo(451.88,260.75);
bunny.lineTo(451.88,260.75);
bunny.lineTo(453.38,264.13);
bunny.lineTo(453.38,264.13);
bunny.lineTo(453.38,264.13);
bunny.lineTo(454.25,266.88);
bunny.lineTo(454.25,266.88);
bunny.lineTo(454.25,266.88);
bunny.lineTo(455.50,271.13);
bunny.lineTo(455.50,271.13);
bunny.lineTo(455.50,271.13);
bunny.lineTo(455.63,274.75);
bunny.lineTo(455.63,274.75);
bunny.lineTo(455.63,274.75);
bunny.lineTo(456.75,276.50);
bunny.lineTo(456.75,276.50);
bunny.lineTo(456.75,276.50);
bunny.lineTo(458.63,278.00);
bunny.lineTo(458.63,278.00);
bunny.lineTo(458.63,278.00);
bunny.lineTo(460.00,278.88);
bunny.lineTo(460.00,278.88);
bunny.lineTo(460.00,278.88);
bunny.lineTo(461.00,280.75);
bunny.lineTo(461.00,280.75);
bunny.lineTo(461.00,280.75);
bunny.lineTo(462.75,281.00);
bunny.lineTo(462.75,281.00);
bunny.lineTo(462.75,281.00);
bunny.lineTo(464.88,281.88);
bunny.lineTo(464.88,281.88);
bunny.lineTo(464.88,281.88);
bunny.lineTo(467.38,283.00);
bunny.lineTo(467.38,283.00);
bunny.lineTo(467.38,283.00);
bunny.lineTo(470.13,284.50);
bunny.lineTo(470.13,284.50);
bunny.lineTo(470.13,284.50);
bunny.lineTo(472.00,286.13);
bunny.lineTo(472.00,286.13);
bunny.lineTo(473.63,287.50);
bunny.lineTo(477.13,290.13);
bunny.lineTo(477.13,290.13);
bunny.lineTo(477.13,290.13);
bunny.lineTo(479.50,292.25);
bunny.lineTo(479.50,292.25);
bunny.lineTo(479.50,292.25);
bunny.lineTo(481.50,295.00);
bunny.lineTo(481.50,295.00);
bunny.lineTo(481.50,295.00);
bunny.lineTo(483.38,299.13);
bunny.lineTo(483.38,299.13);
bunny.lineTo(483.38,299.13);
bunny.lineTo(483.38,303.63);
bunny.lineTo(483.38,303.63);
bunny.lineTo(483.38,303.63);
bunny.lineTo(482.63,308.00);
bunny.lineTo(482.63,308.00);
bunny.lineTo(482.63,308.00);
bunny.lineTo(480.75,311.75);
bunny.lineTo(480.75,311.75);
bunny.lineTo(480.75,311.75);
bunny.lineTo(469.25,325.00);
bunny.lineTo(469.25,325.00);
bunny.lineTo(469.25,325.00);
bunny.lineTo(464.00,330.63);
bunny.lineTo(464.00,330.63);
bunny.lineTo(464.00,330.63);
bunny.lineTo(458.50,337.13);
bunny.lineTo(458.50,337.13);
bunny.lineTo(458.50,337.13);
bunny.lineTo(451.75,345.13);
bunny.lineTo(451.75,345.13);
bunny.lineTo(451.75,345.13);
bunny.lineTo(448.38,349.63);
bunny.lineTo(448.38,349.63);
bunny.lineTo(448.38,349.63);
bunny.lineTo(446.00,353.13);
bunny.lineTo(446.00,353.13);
bunny.lineTo(446.00,353.13);
bunny.lineTo(443.38,357.75);
bunny.lineTo(443.38,357.75);
bunny.lineTo(443.38,357.75);
bunny.lineTo(442.13,361.13);
bunny.lineTo(442.13,361.13);
bunny.lineTo(442.13,361.13);
bunny.lineTo(441.88,367.38);
bunny.lineTo(441.88,367.38);
bunny.lineTo(441.88,367.38);
bunny.lineTo(441.75,371.75);
bunny.lineTo(441.75,371.75);
bunny.lineTo(441.75,371.75);
bunny.lineTo(442.13,375.63);
bunny.lineTo(442.13,375.63);
bunny.lineTo(442.13,375.63);
bunny.lineTo(443.00,381.88);
bunny.lineTo(443.00,381.88);
bunny.lineTo(443.00,381.88);
bunny.lineTo(444.38,385.75);
bunny.lineTo(444.38,385.75);
bunny.lineTo(444.38,385.75);
bunny.lineTo(446.50,390.75);
bunny.lineTo(446.50,390.75);
bunny.lineTo(446.50,390.75);
bunny.lineTo(450.00,396.38);
bunny.lineTo(450.00,396.38);
bunny.lineTo(450.00,396.38);
bunny.lineTo(452.88,399.50);
bunny.lineTo(452.88,399.50);
bunny.lineTo(452.88,399.50);
bunny.lineTo(457.25,404.25);
bunny.lineTo(457.25,404.25);
bunny.lineTo(457.25,404.25);
bunny.lineTo(462.38,409.50);
bunny.lineTo(462.38,409.50);
bunny.lineTo(462.38,409.50);
bunny.lineTo(467.25,414.50);
bunny.lineTo(467.25,414.50);
bunny.lineTo(467.25,414.50);
bunny.lineTo(471.25,418.63);
bunny.lineTo(471.25,418.63);
bunny.lineTo(471.25,418.63);
bunny.lineTo(473.25,421.38);
bunny.lineTo(473.25,421.38);
bunny.lineTo(473.25,421.38);
bunny.lineTo(476.63,426.13);
bunny.lineTo(476.63,426.13);
bunny.lineTo(476.63,426.13);
bunny.lineTo(480.75,431.13);
bunny.lineTo(480.75,431.13);
bunny.lineTo(480.75,431.13);
bunny.lineTo(483.50,435.13);
bunny.lineTo(483.50,435.13);
bunny.lineTo(483.50,435.13);
bunny.lineTo(485.25,439.63);
bunny.lineTo(485.25,439.63);
bunny.lineTo(485.25,439.63);
bunny.lineTo(487.50,444.75);
bunny.lineTo(487.50,444.75);
bunny.lineTo(487.50,444.75);
bunny.lineTo(489.13,448.88);
bunny.lineTo(489.13,448.88);
bunny.lineTo(489.13,448.88);
bunny.lineTo(489.75,453.88);
bunny.lineTo(489.75,453.88);
bunny.lineTo(489.75,453.88);
bunny.lineTo(490.63,459.38);
bunny.lineTo(490.63,459.38);
bunny.lineTo(490.63,459.38);
bunny.lineTo(492.38,466.25);
bunny.lineTo(492.38,466.25);
bunny.lineTo(492.38,466.25);
bunny.lineTo(493.38,472.88);
bunny.lineTo(493.38,472.88);
bunny.lineTo(493.38,472.88);
bunny.lineTo(493.88,477.13);
bunny.lineTo(493.88,477.13);
bunny.lineTo(493.88,477.13);
bunny.lineTo(494.38,480.63);
bunny.lineTo(494.38,480.63);
bunny.lineTo(494.38,480.63);
bunny.lineTo(495.50,483.38);
bunny.lineTo(495.50,483.38);
bunny.lineTo(495.50,483.38);
bunny.lineTo(498.00,485.25);
bunny.lineTo(498.00,485.25);
bunny.lineTo(498.00,485.25);
bunny.lineTo(499.50,488.00);
bunny.lineTo(499.50,488.00);
bunny.lineTo(499.50,488.00);
bunny.lineTo(500.63,491.50);
bunny.lineTo(500.63,491.50);
bunny.lineTo(500.63,491.50);
bunny.lineTo(501.25,497.13);
bunny.lineTo(501.25,497.13);
bunny.lineTo(501.25,497.13);
bunny.lineTo(500.13,501.13);
bunny.lineTo(500.13,501.13);
bunny.lineTo(500.13,501.13);
bunny.lineTo(499.13,505.63);
bunny.lineTo(499.13,505.63);
bunny.lineTo(499.13,505.63);
bunny.lineTo(497.88,507.88);
bunny.lineTo(497.88,507.88);
bunny.lineTo(497.88,507.88);
bunny.lineTo(495.88,512.25);
bunny.lineTo(495.88,512.25);
bunny.lineTo(495.88,512.25);
bunny.lineTo(494.38,516.25);
bunny.lineTo(494.38,516.25);
bunny.lineTo(494.38,516.25);
bunny.lineTo(493.25,518.63);
bunny.lineTo(493.25,518.63);
bunny.lineTo(493.25,518.63);
bunny.lineTo(491.88,521.88);
bunny.lineTo(491.88,521.88);
bunny.lineTo(491.88,521.88);
bunny.lineTo(489.38,524.00);
bunny.lineTo(489.38,524.00);
bunny.lineTo(489.38,524.00);
bunny.lineTo(489.13,526.63);
bunny.lineTo(489.13,526.63);
bunny.lineTo(489.13,526.63);
bunny.lineTo(488.13,528.75);
bunny.lineTo(488.13,528.75);
bunny.closePath();
g2.draw(bunny);
Color gold = new Color(255,215,0);
g2.setColor(gold);
g2.fill(bunny);
Path2D chocoears = new Path2D.Float();
chocoears.moveTo(473.63, 287.50);
chocoears.lineTo(473.63,287.50);
chocoears.lineTo(477.13,290.13);
chocoears.lineTo(477.13,290.13);
chocoears.lineTo(477.13,290.13);
chocoears.lineTo(479.50,292.25);
chocoears.lineTo(479.50,292.25);
chocoears.lineTo(479.50,292.25);
chocoears.lineTo(481.50,295.00);
chocoears.lineTo(481.50,295.00);
chocoears.lineTo(481.50,295.00);
chocoears.lineTo(483.38,299.13);
chocoears.lineTo(483.38,299.13);
chocoears.lineTo(483.38,299.13);
chocoears.lineTo(483.38,303.63);
chocoears.lineTo(483.38,303.63);
chocoears.lineTo(483.38,303.63);
chocoears.lineTo(482.63,308.00);
chocoears.lineTo(482.63,308.00);
chocoears.lineTo(482.63,308.00);
chocoears.lineTo(480.75,311.75);
chocoears.lineTo(480.75,311.75);
chocoears.lineTo(480.75,311.75);
chocoears.lineTo(469.25,325.00);
chocoears.lineTo(469.25,325.00);
chocoears.lineTo(469.25,325.00);
chocoears.lineTo(464.00,330.63);
chocoears.lineTo(464.00,330.63);
chocoears.lineTo(464.00,330.63);
chocoears.lineTo(458.50,337.13);
chocoears.lineTo(458.50,337.13);
chocoears.lineTo(458.50,337.13);
chocoears.lineTo(451.75,345.13);
chocoears.lineTo(451.75,345.13);
chocoears.lineTo(451.75,345.13);
chocoears.lineTo(442.33,351.00);
chocoears.lineTo(442.33,351.00);
chocoears.lineTo(442.33,351.00);
chocoears.lineTo(435.33,351.00);
chocoears.lineTo(435.33,351.00);
chocoears.lineTo(435.33,351.00);
chocoears.lineTo(432.00,349.00);
chocoears.lineTo(432.00,349.00);
chocoears.lineTo(432.00,349.00);
chocoears.lineTo(427.00,348.67);
chocoears.lineTo(427.00,348.67);
chocoears.lineTo(427.00,348.67);
chocoears.lineTo(420.00,342.67);
chocoears.lineTo(420.00,342.67);
chocoears.lineTo(420.00,342.67);
chocoears.lineTo(415.33,339.33);
chocoears.lineTo(415.33,339.33);
chocoears.lineTo(415.33,339.33);
chocoears.lineTo(412.00,341.00);
chocoears.lineTo(412.00,341.00);
chocoears.lineTo(412.00,341.00);
chocoears.lineTo(408.33,337.00);
chocoears.lineTo(408.33,337.00);
chocoears.lineTo(408.33,337.00);
chocoears.lineTo(407.33,333.33);
chocoears.lineTo(407.33,333.33);
chocoears.lineTo(407.33,333.33);
chocoears.lineTo(403.67,329.67);
chocoears.lineTo(403.67,329.67);
chocoears.lineTo(403.67,329.67);
chocoears.lineTo(399.00,331.67);
chocoears.lineTo(399.00,331.67);
chocoears.lineTo(399.00,331.67);
chocoears.lineTo(396.33,329.33);
chocoears.lineTo(396.33,329.33);
chocoears.lineTo(396.33,329.33);
chocoears.lineTo(394.33,326.67);
chocoears.lineTo(394.33,326.67);
chocoears.lineTo(394.33,326.67);
chocoears.lineTo(386.67,326.33);
chocoears.lineTo(386.67,326.33);
chocoears.lineTo(386.67,326.33);
chocoears.lineTo(382.33,320.67);
chocoears.lineTo(382.33,320.67);
chocoears.lineTo(382.33,320.67);
chocoears.lineTo(378.00,322.00);
chocoears.lineTo(378.00,322.00);
chocoears.lineTo(378.00,322.00);
chocoears.lineTo(372.00,320.00);
chocoears.lineTo(372.00,320.00);
chocoears.lineTo(372.00,320.00);
chocoears.lineTo(373.33,318.00);
chocoears.lineTo(373.33,318.00);
chocoears.lineTo(373.33,318.00);
chocoears.lineTo(371.33,315.67);
chocoears.lineTo(371.33,315.67);
chocoears.lineTo(371.33,315.67);
chocoears.lineTo(365.33,316.00);
chocoears.lineTo(365.33,316.00);
chocoears.lineTo(365.33,316.00);
chocoears.lineTo(355.25,312.00);
chocoears.lineTo(355.25,312.00);
chocoears.lineTo(355.25,312.00);
chocoears.lineTo(361.00,310.88);
chocoears.lineTo(361.00,310.88);
chocoears.lineTo(361.00,310.88);
chocoears.lineTo(364.50,309.75);
chocoears.lineTo(364.50,309.75);
chocoears.lineTo(364.50,309.75);
chocoears.lineTo(367.75,307.50);
chocoears.lineTo(367.75,307.50);
chocoears.lineTo(367.75,307.50);
chocoears.lineTo(373.25,302.50);
chocoears.lineTo(373.25,302.50);
chocoears.lineTo(373.25,302.50);
chocoears.lineTo(379.13,296.13);
chocoears.lineTo(379.13,296.13);
chocoears.lineTo(379.13,296.13);
chocoears.lineTo(384.25,290.13);
chocoears.lineTo(384.25,290.13);
chocoears.lineTo(384.25,290.13);
chocoears.lineTo(389.25,283.88);
chocoears.lineTo(389.25,283.88);
chocoears.lineTo(389.25,283.88);
chocoears.lineTo(393.25,279.50);
chocoears.lineTo(393.25,279.50);
chocoears.lineTo(393.25,279.50);
chocoears.lineTo(396.63,275.50);
chocoears.lineTo(396.63,275.50);
chocoears.lineTo(396.63,275.50);
chocoears.lineTo(400.50,271.38);
chocoears.lineTo(400.50,271.38);
chocoears.lineTo(400.50,271.38);
chocoears.lineTo(406.25,266.75);
chocoears.lineTo(406.25,266.75);
chocoears.lineTo(406.25,266.75);
chocoears.lineTo(411.50,262.13);
chocoears.lineTo(411.50,262.13);
chocoears.lineTo(411.50,262.13);
chocoears.lineTo(414.88,259.75);
chocoears.lineTo(414.88,259.75);
chocoears.lineTo(414.88,259.75);
chocoears.lineTo(420.25,256.63);
chocoears.lineTo(420.25,256.63);
chocoears.lineTo(420.25,256.63);
chocoears.lineTo(424.63,253.88);
chocoears.lineTo(424.63,253.88);
chocoears.lineTo(424.63,253.88);
chocoears.lineTo(427.50,252.88);
chocoears.lineTo(427.50,252.88);
chocoears.lineTo(427.50,252.88);
chocoears.lineTo(431.13,251.50);
chocoears.lineTo(431.13,251.50);
chocoears.lineTo(431.13,251.50);
chocoears.lineTo(434.25,251.13);
chocoears.lineTo(434.25,251.13);
chocoears.lineTo(434.25,251.13);
chocoears.lineTo(437.63,251.00);
chocoears.lineTo(437.63,251.00);
chocoears.lineTo(437.63,251.00);
chocoears.lineTo(442.50,252.25);
chocoears.lineTo(442.50,252.25);
chocoears.lineTo(442.50,252.25);
chocoears.lineTo(445.50,253.75);
chocoears.lineTo(445.50,253.75);
chocoears.lineTo(445.50,253.75);
chocoears.lineTo(447.88,255.25);
chocoears.lineTo(447.88,255.25);
chocoears.lineTo(447.88,255.25);
chocoears.lineTo(450.50,258.25);
chocoears.lineTo(450.50,258.25);
chocoears.lineTo(450.50,258.25);
chocoears.lineTo(451.88,260.75);
chocoears.lineTo(451.88,260.75);
chocoears.lineTo(451.88,260.75);
chocoears.lineTo(453.38,264.13);
chocoears.lineTo(453.38,264.13);
chocoears.lineTo(453.38,264.13);
chocoears.lineTo(454.25,266.88);
chocoears.lineTo(454.25,266.88);
chocoears.lineTo(454.25,266.88);
chocoears.lineTo(455.50,271.13);
chocoears.lineTo(455.50,271.13);
chocoears.lineTo(455.50,271.13);
chocoears.lineTo(455.63,274.75);
chocoears.lineTo(455.63,274.75);
chocoears.lineTo(455.63,274.75);
chocoears.lineTo(456.75,276.50);
chocoears.lineTo(456.75,276.50);
chocoears.lineTo(456.75,276.50);
chocoears.lineTo(458.63,278.00);
chocoears.lineTo(458.63,278.00);
chocoears.lineTo(458.63,278.00);
chocoears.lineTo(460.00,278.88);
chocoears.lineTo(460.00,278.88);
chocoears.lineTo(460.00,278.88);
chocoears.lineTo(461.00,280.75);
chocoears.lineTo(461.00,280.75);
chocoears.lineTo(461.00,280.75);
chocoears.lineTo(462.75,281.00);
chocoears.lineTo(462.75,281.00);
chocoears.lineTo(462.75,281.00);
chocoears.lineTo(464.88,281.88);
chocoears.lineTo(464.88,281.88);
chocoears.lineTo(464.88,281.88);
chocoears.lineTo(467.38,283.00);
chocoears.lineTo(467.38,283.00);
chocoears.lineTo(467.38,283.00);
chocoears.lineTo(470.13,284.50);
chocoears.lineTo(470.13,284.50);
chocoears.lineTo(470.13,284.50);
chocoears.lineTo(472.00,286.13);
chocoears.lineTo(472.00,286.13);
chocoears.closePath();
g2.draw(chocoears);
Color milkChocolate = new Color(111,68,51);
g2.setColor(milkChocolate);
g2.fill(chocoears);
//Grass
Rectangle grass = new Rectangle(0,525,getWidth(),100);
Color lawnGreen = new Color(124,252,0);
g2.setColor(lawnGreen);
g2.fill(grass);
List<Arc2D> blades = new ArrayList<Arc2D>();
for (int x = 0; x < getWidth(); x += 10) {
blades.add(new Arc2D.Double(x, 500, 10, 35, 105, 180, Arc2D.OPEN));
blades.add(new Arc2D.Double(x - 5, 510, 10, 35, 105, 180, Arc2D.OPEN));
blades.add(new Arc2D.Double(x, 520, 10, 35, 105, 180, Arc2D.OPEN));
}
Color yellowGreen = new Color(107, 142, 35);
g2.setColor(yellowGreen);
for (Shape blade : blades) {
g2.draw(blade);
}
Ellipse2D.Double circle = new Ellipse2D.Double(60,100,25,25);
g2.setColor(Color.RED);
g2.fill(circle);
Rectangle box = new Rectangle(150,100,20,80);
g2.setColor(Color.YELLOW);
g2.fill(box);
}
}
Whatever you do I would
create the Path2D objects outside of the paintComponent() method.
add each Path2D object to an ArrayList
in the paintComponent() method you can iterate through the ArrayList to paint each Path2D
Or another approach is to just have a method that:
creates each Path2D object when the class is created
then you paint the Path2D object to a BufferedImage
now that you have a BufferedImage you can create an ImageIcon and Just use a JLabel in you app and you don't need the custom panel.
Heres 2 options I would consider for cleaning up the pathing.
Use SVG, one library I know is Batik found at: http://xmlgraphics.apache.org/batik/
Once I did a project where the paths I needed would be created in photoshop then exported to Illustrator. The file format was each action was line delineated, each line was space delineated and consisted of a set of points with the last entry the command name. Here was a sample input.
10 10 m
15 15 l
10 10 12 12 v
As you can see you just read the file, create your path and do an if test for the last letter on the line and use the appropriate command with for the points. Of course you can make up your own format or procedures but it sure was nice using photoshop for me :)

Categories

Resources