swing - java awt event queue/dispatch thread unknown source errors? -



swing - java awt event queue/dispatch thread unknown source errors? -

i tried run code create image using jframe

main class

import java.awt.*; import javax.swing.jframe; public class main { public static void main(string[] args){ jframe f = new jframe(); f.setdefaultcloseoperation(jframe.exit_on_close); f.settitle("kek"); f.add (new graphicssurface()); f.setsize(512, 512); f.setlocationrelativeto(null); f.setvisible(true); } }

graphicssurface class

import java.awt.color; import java.awt.graphics; import java.awt.graphics2d; import javax.swing.jcomponent; public class graphicssurface extends jcomponent { public graphicssurface() { } public void paint (graphics g) { int end = 0; long redint = 0, greenint = 0, blueint = 0; int xstart = 0, ystart = 0, xend = 0, yend = 0; double y = 0, x = 0; double width = 80; double angle = 0; double endpoint = 255; double curveintensitya = 1.4, curveintensityb = -0.9; double curvestarta = 30, curvestartb = 150; double curvelengtha = 15, curvelengthb = 30; double redvalue = 0, greenvalue = 0, bluevalue = 0; while (end == 0) { graphics2d g2d = (graphics2d) g; redvalue = 100 + (y / 2.56); greenvalue = 50 + (y / 1.28); bluevalue = 200 + (y / 5.12); redint = math.round(redvalue); greenint = math.round(greenvalue); blueint = math.round(bluevalue); if (y >= curvestarta && y < (curvestarta + curvelengtha)) { angle = angle + (curveintensitya / curvelengtha); } if (y >= curvestartb && y < (curvestartb + curvelengthb)) { angle = angle + (curveintensityb / curvelengthb); } width = width + angle; if (width > 512) { width = 512; } x = math.round(width); xend = (int) x; ystart = (int) y; yend = ystart; y = y + 1; if (y > endpoint) { end = 1; } g2d.setcolor(new color(redint, greenint, blueint, 255)); g2d.drawline(xstart, ystart, xend, yend); } } }

but got in console:

at java.awt.eventqueue.dispatchevent(unknown source) @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source) @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.pumpevents(unknown source) @ java.awt.eventdispatchthread.run(unknown source)

i'd know caused problem , should prepare it.

the issue line

g2d.setcolor(new color(redint, greenint, blueint, 255));

the type of redint, greenint , blueint in code of type long. constructor color takes in either int or long.

you can refer documentation here

so prepare problem: alter these types long int , appropriate casting.

java swing jframe awt event-dispatch-thread

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -