java


In Java, how can I draw on a JPanel using data from another class?


Is there any way to draw on a JPanel using data from another class? Here is the code I tried:
class overlay extends JPanel {
public void paintComponent(Graphics g, lineStore data) {
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.BLUE);
for (int i = 0; i < data.length; i++) {
g.drawLine(data[i].x1,data[i].y1,data[i].x2,data[i].y2);
}
}
}
Here you go:
class overlay extends JPanel {
private lineStore data;
public overlay(lineStore data) {
this.data = data;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.BLUE);
for (int i = 0; i < data.length; i++) {
g.drawLine(data[i].x1,data[i].y1,data[i].x2,data[i].y2);
}
}
}
To use it do:
lineStore data; //create lineStore here
overlay panel = new overlay(data);
panel.repaint();

Related Links

Closing Inactive Sessions using BasicDataSource
java sorting string with numbers including symbols <,>=
Good Reason to use java.util.Date in an API
Which datatype to use as queue in Dijkstra's algorithm?
Java seems to ignore -Xms and -Xmx options
adding action listener for the node in a tree
Localizations: converting english text to Chinese text [duplicate]
calling a new method in java from mxml produces “cannot invoke method” error
Java, Classpath, Classloading => Multiple Versions of the same jar/project
SSLException: Received fatal alert: unexpected_message
Why not encrypt the Java bytecode instead of obfuscate it?
Display SVG file
How do I set the horizontal gap for just one part of a FlowLayout?
should a db connection be a singleton?
Need help to fix JVM error, related to launch4j
Error while Publishing WSDL

Categories

HOME
twitter
testing
pdf
variables
listview
coq
keycloak
nullpointerexception
fft
grep
jira
microservices
ckeditor
alpha
in-app-purchase
esper
cloudkit
offline
google-apps-marketplace
orchardcms
dtrace
serverless-framework
telephony
tostring
ef-migrations
ehcache
web-sql
excel-2007
emgucv
h2db
sparse-matrix
brunch
minitab
compatibility
nat
socialengine
nameservers
siesta-swift
framemaker
hybridauth
repo
android-kernel
google-api-nodejs-client
normal-distribution
picasso
http-digest
appfabric
stacked
vxworks
swift3.0.2
gesture
serverside-rendering
code-search-engine
ruby-on-rails-3.1
nomethoderror
vao
s
node-sass
appcompat
chain-builder
sybase-asa
migradoc
savon
hill-climbing
bluegiga
photobucket
execute
interrupted-exception
dundas
dereference
operator-precedence
wordpress-theme-customize
flask-cors
funcunit
message-driven-bean
xsockets.net
cos
shellexecute
html-editor
free-variable
viewswitcher
nsmanagedobject
zpt
deobfuscation
tomcat-valve
html-input
fluent-interface
revisions
firefox4
webkit.net
microsoft-virtualization
geneva-server
lzh

Resources

Encrypt Message