Drawing a DAG
I need advice on how to go about drawing a DAG (directional acyclic graph). Alot of stuff on the Internet about traversing a DAG and analyzing a DAG but I couldn't find any info about a algorithm to actually draw the graph. Anyone know any resources that can help ?
Try the following. You almost had it correct.
import java.awt.*;
import javax.swing.*;
import com.ibm.graph.*;
import com.ibm.graph.layout.*;
import com.ibm.graph.draw.*;
import com.ibm.graph.ext.visual.*;
import com.ibm.research.util.*;
import java.util.*;
public class GraphDraw extends Canvas{
private Graph graph;
private int xOrigin = 200;
private int yOrigin = 200;
private int layout = 0;
public GraphDraw(int layout)
// create graph
this.graph = new Graph();
this.layout = layout;
public void setup() {
try {
// set up the graph
Vertex v1 = new Vertex();
v1.setName("A");
Vertex v2 = new Vertex();
v2.setName("B");
Vertex v3 = new Vertex();
v3.setName("C");
Vertex v4 = new Vertex();
v4.setName("D");
Edge e12 = new Edge(v1, v2);
Edge e13 = new Edge(v1, v3);
Edge e14 = new Edge(v1,v4);
Edge e23 = new Edge(v2,v3);
Edge e24 = new Edge(v2,v4);
Edge e34 = new Edge(v3,v4);
graph.add(v1);
graph.add(v2);
graph.add(v3);
graph.add(v4);
graph.add(e12);
graph.add(e13);
graph.add(e14);
graph.add(e23);
graph.add(e24);
graph.add(e34);
// tell graph how to lay itself out
graph.setRoot(v1, true);
if(layout==1)
System.out.println("Using Glow97 layout");
LayoutGlow97 manager = new LayoutGlow97();
manager.setOptimalEdgeLength(100.0);
manager.setRepulsionConstant(10.0);
manager.setIterationsImproveVertexLocation(100);
graph.setGraphLayoutManager(manager);
} else { // default layout
System.out.println("Using DAG layout");
// the set x and y of the root does not appear to work.
// thats a bit strange, however a work around exists in the paint method
LayoutDAG manager = new LayoutDAG();
manager.setX0(xOrigin);
manager.setY0(yOrigin);
manager.setXSpaceMultiplier(2);
manager.setYSpaceMultiplier(2);
graph.setGraphLayoutManager(manager);
// The following has to be done after the edges/vertices are added to the
// graph. (does not work otherwise)
// you were on the correct path here. Set up a method of drawing
// say how graph will be drawn
DrawNetEdgesThenVertices dn = new DrawNetEdgesThenVertices();
graph.setDrawable(dn);
// say how vertices will be drawn
Draw3VertexRectangleKeyText dv = new Draw3VertexRectangleKeyText();
dv.setColorOutline(java.awt.Color.BLUE);
graph.setDrawableVertices(graph,dv);
// say how edges will be drawn
Draw2EdgeLine de = new Draw2EdgeLine();
de.setColorPath(java.awt.Color.RED);
graph.setDrawableEdges(graph,de);
graph.layout();
} catch (Exception e) {
e.printStackTrace();
this.setSize(600, 400);
this.setVisible(true);
public void paint (Graphics g) {
try {
super.paint(g);
// quick hack to make the origin of the root work (translate the graphics to
// the required offset) This may not work with other Layouts
g.translate(xOrigin,yOrigin);
graph.draw(g);
} catch (Exception e) { e.printStackTrace(); }
public static void main(String[] args) {
if(args.length!=1) {
System.out.println("please enter a layout to use");
System.exit(1);
int layout = 0;
try{
layout = Integer.parseInt(args[0]);
}catch(NumberFormatException nfe) {
System.out.println("Error. You did not enter an integer");
System.exit(2);
JFrame f = new JFrame();
f.setSize(800,600);
GraphDraw gd = new GraphDraw(layout);
gd.setup();
f.getContentPane().add(gd);
f.show();
}The LayoutDAG layout method does not seem to honour the root positions
that you specify. Don't know why but the easy work around is to
translate the graphics context before you draw to it. (see the paint
method).
The Glow97 algorithm is a bit more tricky to use. It is an iterative
optimisation technique. This means that the graphics can appear almost
anywhere on the screen. So you will have to find where they are before
you attempt to draw them or they may well be off screen.
The Glow97 does allow you to refine the layout if you arn't satisfied.
I'm still trying to figure out the best way of drawing buttons instead
of vertices. It will probably involve subclassing one of the Draw?Vertex
classes to draw a button rather then a rectangle or oval.
matfud
Similar Messages
-
Dagi stylus review - works VERY WELL with S10-3t
For those of you interested, I got my Dagi stylus today ordered via ebay for $12 shipped.
It looks very nice, feels good in the hand and is lightweight. The tip is thin and flexible and looks a bit fragile, but seems to be glued on pretty strong.
I tested this with regular touch points, drawing and writing. It worked great for each. The dot in the center of the tip makes for a very accurate touch point. I calibrated the system using it and it was a little tough because some of the points are on the VERY edge of the screen. The 2s10-3t has a gap between the screen plastic and the actual screen and the stylus actually slides underneath to hit the points. After calibration, this isn't an issue.
So, it is way more accurate than the pogo and also less of a risk to scratch the screen. It flows well so I can use cursive and fine for printing also. I strongly recommend this to anyone looking for a stylus solution...it is so far the best I've seen. This thing also works on the iPhone for those wanting dual-purpose. I'll try to post a video of performance soon.
DaveHello,
Your description sounds very similar to what I have. Mine did come in a box with DAGi on it, via eBay.
The shaft of the pen is light aluminum I think. There is a section near the tip that is silver and to me feels like plastic.
The tip is a small flexible circle about 1/2 the diameter of a penny...maybe a little bigger than a pencil eraser. It is VERY flexible and appears to be attached to the silver part of the pen with glue.
In the center of the plastic circle is a small red/orange dot. This dot is the actual touch poing on the pen, nothing else. I can tell you that I have NO trouble at all getting the pen to respond on my tablet. I recommend keeping the entire surface in contact with the screen though to keep your movements consistent.
If you aren't getting any sensitivity at all, perhaps it is a fake, or even broken. My feeling is that the main shaft of the pen being metal sends signal down thru the silver part and onto the dot. I couldn't begin to understand the science of this however. My friend also ordered one of these for his iPhone and his came in a box. His is black, mine came in a redish/purple color.
I hope that helps you solve the mystery...
Dave -
Need Help to Draw and Drag Triangle - URGENT
Hi everyone - I am developing various proofs of the pythagora's theorem
and the following code draws a triangle on screen and the proof follows -
but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
PLEASE HELP
the code is as follows
MAIN CLASS
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
public class TestProof {
TestControl control; // the controls for the visual proof
TestView view; // the drawing area to display proof
// called upon class creation
public TestProof() {
view = new TestView();
view.setBackground(Color.WHITE);
control = new TestControl(view);
Frame f = new Frame("Pythagoras");
f.add(view,"Center");
f.add(control,"South");
f.setSize(600,600);
f.setBackground(Color.lightGray);
f.addMouseMotionListener(
new MouseMotionListener() { //anonymous inner class
//handle mouse drag event
public void mouseMoved(MouseEvent e) {
System.out.println("Mouse " + e.getX() +"," + e.getY());
public void mouseDragged(MouseEvent e) {
System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
JMenu File = new JMenu("File");
JMenuItem Exit = new JMenuItem("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitActionPerformed(evt);
JMenuBar menuBar = new JMenuBar();
menuBar.add(File);
File.add(Exit);
f.add(menuBar,"North");
f.show();
private JMenuBar getMenuBar() {
JMenu File = new JMenu("File");
JMenuItem Exit = new JMenuItem("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitActionPerformed(evt);
JMenuBar menuBar = new JMenuBar();
menuBar.add(File);
File.add(Exit);
return menuBar;
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
// for standalone use
public static void main(String args[]) {
TestProof TP = new TestProof();
}Test VIEW
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.text.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestView extends Canvas {
int TRANSLUCENT = 1;
int sequence; // sequencer that determines what should be drawn
// notes matter
int noteX = 100; // note coordinates
int noteY = 60;
int fontSize = 11; // font size
int lineSpacing // space between two consecutive lines
= fontSize + 2;
Font noteFaceFont; // font used to display notes
// objects matter
Polygon tri; // right-angled triangle with sides A, B, and C
Polygon tri1;
Polygon sqrA; // square with side of length A
Polygon sqrB; // square with side of length B
Polygon sqrC; // square with side of length C
Polygon parA; // parallelogram of base A and height A
Polygon parB; // parallelogram of base B and height B
Polygon poly1;
Polygon poly2;
Polygon poly3;
Polygon poly4;
Polygon poly5;
Polygon poly6;
int X0 = 350; // coordinates of triangle
int Y0 = 350;
int A = 90;//60; // triangle size
int B = 120;//80;
int C = 150;//100;
//CORDS of 2nd triangle
int X1 = 350;
int Y1 = 500;
// notes: three lines per note
String notes[] = {
// note 0
// note 1
// note 2
// note 3
// note 4
// note 5
// note 6
// note 7
// note 8
// note 9
// note 10
// note 11
// note 12
// note 13
// note 14
// constructor
public TestView() {
addMouseMotionListener(
new MouseMotionListener() { //anonymous inner class
//handle mouse drag event
public void mouseMoved(MouseEvent e) {
System.out.println("Mouse " + e.getX() +"," + e.getY());
public void mouseDragged(MouseEvent e) {
System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
// set font
noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
// (coordinates specified w.r.t. to P0, unless otherwise specified)
// create the triangle
tri = new Polygon();
tri.addPoint(0, 0); // add P0 coordinate
tri.addPoint(A*A/C, -A*B/C); // add A3 coordinate
tri.addPoint(C, 0); // add C1 coordinate
tri.translate(X0, Y0); // place triangle
tri1 = new Polygon();
tri1.addPoint(0,0); // add P0 coordinate
tri1.addPoint(A*A/C +38, +A*B/C); // add A3 coordinate
tri1.addPoint(C, 0); // add C1 coordinate
tri1.translate(X1, Y1);
// create square of side A
sqrA = new Polygon();
sqrA.addPoint(0, 0); // add P0 coordinate
sqrA.addPoint(-A*B/C, -A*A/C); // add A1 coordinate
sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C); // add A2 coordinate
sqrA.addPoint(A*A/C, -A*B/C); // add A3 coordinate
sqrA.translate(X0, Y0); // place square
// create square of side B
// warning: the coordinate of this object are specified relative to C1
sqrB = new Polygon();
sqrB.addPoint(0, 0); // add C1 coordinate
sqrB.addPoint(B*A/C, -B*B/C); // add B1 coordinate
sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C); // add B2 coordinate
sqrB.addPoint(-B*B/C, -B*A/C); // add A3 coordinate
sqrB.translate(X0 + C, Y0); // place square
// create square of side C
sqrC = new Polygon();
sqrC.addPoint(0, 0); // add P0 coordinate
sqrC.addPoint(C, 0); // add C1 coordinate
sqrC.addPoint(C, C); // add C2 coordinate
sqrC.addPoint(0, C); // add C3 coordinate
sqrC.translate(X0, Y0); // place square
poly1 = new Polygon();
poly1.addPoint(405,279);
poly1.addPoint(413,350);
poly1.addPoint(432,500);
poly1.addPoint(442,571);
poly1.addPoint(500,500);
poly1.addPoint(500,350);
poly2 = new Polygon();
poly2.addPoint(279,297);
poly2.addPoint(404,280);
poly2.addPoint(571,254);
poly2.addPoint(500,350);
poly2.addPoint(350,350);
//Polygon 3
poly3 = new Polygon();
poly3.addPoint(404,280);
poly3.addPoint(350,350);
poly3.addPoint(414,350);
poly4 = new Polygon();
poly4.addPoint(350,350);
poly4.addPoint(350,500);
poly4.addPoint(442,572);
poly4.addPoint(433,500);
poly4.addPoint(414,350);
poly5 = new Polygon();
poly5.addPoint(476,183);
poly5.addPoint(332,225);
poly5.addPoint(278,295);
poly5.addPoint(404,279);
poly5.addPoint(571,254);
poly6= new Polygon();
poly6.addPoint(405,278);
poly6.addPoint(332,224);
poly6.addPoint(476,182);
// create parallelogram of height A
parA = new Polygon();
parA.addPoint(0, 0); // add P0 coordinate
parA.addPoint(0, C); // add C3 coordinate
parA.addPoint(A*A/C, C - A*B/C); // add Q0 coordinate
parA.addPoint(A*A/C, -A*B/C); // add A3 coordinate
parA.translate(X0,Y0); // place parallelogram
// create parallelogram of height B
// warning: the coordinate of this object are specified from C1
parB = new Polygon();
parB.addPoint(0, 0); // add C1 coordinate
parB.addPoint(-B*B/C, -B*A/C); // add A3 coordinate
parB.addPoint(A*A/C - C, C - A*B/C); // add Q0 coordinate
parB.addPoint(0, C); // add C2 coordinate
parB.translate(X0 + C, Y0);
// place parallelogram
// depending on the sequence number we draw certain objects
public void paint(Graphics gfx) {
super.paint(gfx);
Graphics2D g = (Graphics2D) gfx;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// text first, then objects (and animation)
// we always output some notes
g.drawString(notes[3*sequence], noteX, noteY);
g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
// the object are drawn in an order so that they are properly overlapped
if(sequence == 13) {
g.setColor(Color.green);
g.fillPolygon(poly1);
g.fillPolygon(poly2);
g.fillPolygon(poly3);
g.fillPolygon(poly4);
g.fillPolygon(poly5);
g.setColor(Color.RED);
g.setColor(Color.GREEN);
g.drawLine(413,351,433,499);
g.setColor(Color.white);
g.fillPolygon(tri);
g.fillPolygon(tri1);
g.fillPolygon(poly6);
if(sequence == 12 ) {
g.setColor(Color.green);
g.fillPolygon(poly1);
g.fillPolygon(poly2);
g.fillPolygon(poly3);
g.fillPolygon(poly4);
g.fillPolygon(poly5);
g.setColor(Color.BLACK);
if(sequence == 11){
g.setColor(Color.green);
g.fillPolygon(poly1);
g.fillPolygon(poly3);
g.fillPolygon(poly4);
g.setColor(Color.BLACK);
if(sequence == 8 ){
g.setColor(Color.green);
g.fillPolygon(poly5);
g.setColor(Color.MAGENTA);
g.drawString("E",578,254);
g.drawString("D",268,302);
g.setColor(Color.black);
g.drawArc(250,150,350,250,320,65);
else if (sequence == 9 ){
g.setColor(Color.green);
g.fillPolygon(poly2);
g.setColor(Color.MAGENTA);
g.drawString("E",578,254);
g.drawString("D",268,302);
g.setColor(Color.black);
g.drawArc(250,150,350,250,320,65);
if( sequence == 10){
g.setColor(Color.green);
g.fillPolygon(poly2);
g.fillPolygon(poly5);
g.setColor(Color.black);
g.setColor(Color.MAGENTA);
g.drawString("E",578,254);
g.drawString("D",268,302);
g.setColor(Color.black);
g.drawArc(250,150,350,250,320,65);
if(sequence == 7){
g.setColor(Color.green);
g.fillPolygon(poly2);
g.setColor(Color.MAGENTA);
g.drawString("E",578,254);
g.drawString("D",268,302);
g.setColor(Color.black);
if(sequence == 6){
g.setColor(Color.yellow);
g.fillPolygon(poly2);
g.setColor(Color.green);
g.fillPolygon(poly3);
g.setColor(Color.blue);
g.fillPolygon(poly4);
g.setColor(Color.black);
g.drawArc(250,175,350,275,300,65);
//g.drawArc(250,150,350,250,320,65);
g.drawLine( 606,309,599,299);
g.drawLine(592,313, 599,299);
g.drawString("+90 degrees",605,378);
if (sequence == 5 ) {
g.setColor(Color.yellow);
g.fillPolygon(poly2);
g.setColor(Color.black);
if (sequence == 4) {
g.setColor(Color.YELLOW);
g.fillPolygon(poly1);
g.setColor(Color.black);
g.drawArc(319,310,250,195,89,-35);
g.drawLine(499,319, 492,312);
g.drawLine(499,319, 492,325);
g.drawArc(200,180, 233,238,-120,-60);
g.drawLine(200,298, 208,309);
g.drawLine(200,298, 194,313);
g.drawString("-90 degrees",227,347);
if (sequence >= 3) {
g.drawLine(404,279,442,572);
// draw the squares
if (sequence >= 2) {
g.drawLine(278,296,572,254);
// draw the squares
if (sequence >= 1) {
g.drawLine(333,224,476,182);
g.drawPolygon(tri1);
// always draw the triangle
g.drawPolygon(tri);
g.drawPolygon(sqrA);
g.drawPolygon(sqrB);
g.drawPolygon(sqrC);
g.setColor(Color.MAGENTA);
g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
g.drawString("A",
X0 + A*A/(2*C) - fontSize*A/B/2,
Y0 - A*B/(2*C) - lineSpacing*A/B);
g.drawString("B",
X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
Y0 - B*A/(2*C) - lineSpacing*A/B);
public void redraw(int sequence) {
this.sequence = sequence;
repaint();
}TEST CONTROL
* TestControl.java
* Created on 28 February 2005, 11:16
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.JFrame;
* @author Kripa Bhojwani
public class TestControl extends Panel implements ActionListener {
TestView view;
int sequence; // event sequence
// constructor
public TestControl(TestView view) {
Button b = null;
Label label = new Label("A^2 ");
this.view = view; // initialize drawble area
sequence = 0; // initialize sequence
b = new Button("Prev");
b.addActionListener(this);
add(b);
b = new Button("Next");
b.addActionListener(this);
add(b);
add(label);
// exported method
public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand();
if (label.equals("Prev")) {
if (sequence >0) {
--sequence;
else {
if (sequence < 15) {
++sequence;
this.setEnabled(false); // disable the controls
view.redraw(sequence);
this.setEnabled(true); // enable the controls
}Please help --- really need to sort this out...
THANKSOne of the problems you face is that it is hard to recognise which parts of your code are drawing the triangle. This is because you are writing code in a procedural way rather than an object oriented way.
In object oriented code you would have a triangle object that could draw itself. You would create the triangle object by specifying its sizes and angles in some way. Then it should be easy to change the triangles sizes and angles and ask all the drawn objects to redraw themselves. -
Possibility of drawing numbers on java bouncing balls?
Can anyone show me how to put numbers on these moving balls in my code. I need the numbers 1-60 on them. I have two sets the red and white. Here is my code. Any help is appreciated. I am trying to write a program to represent the powerball.
import java.awt.*;
import java.applet.*;
import java.util.*;
import javax.swing.*;
import java.awt.Rectangle;
class CollideBall{
int width, height;
public static final int diameter=20;
//coordinates and value of increment
double x, y, xinc, yinc, coll_x, coll_y;
boolean collide;
Color color;
Graphics g;
Rectangle r;
//the constructor
public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
width=w;
height=h;
this.x=x;
this.y=y;
this.xinc=xinc;
this.yinc=yinc;
color=c;
r=new Rectangle(150,80,130,90);
public double getCenterX() {return x+diameter/2;}
public double getCenterY() {return y+diameter/2;}
public void alterRect(int x, int y, int w, int h){
r.setLocation(x,y);
r.setSize(w,h);
public void move(){
if (collide){
double xvect=coll_x-getCenterX();
double yvect=coll_y-getCenterY();
if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
xinc=-xinc;
if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
yinc=-yinc;
collide=false;
x+=xinc;
y+=yinc;
//when the ball bumps against a boundary, it bounces off
//ball width is 6 so if the ball becomes less then 6 it is touching the frame
//if ball is greater than the entire width-the diameter of the rectangle, then the ball is just touching the frame of the rectangle and must switch to negative to go in opposit direction
if(x<6 || x>width-diameter){
xinc=-xinc;
x+=xinc;
//same thing as about just about the Y-axis instead of the x-axis
if(y<6 || y>height-diameter){
yinc=-yinc;
y+=yinc;
public void hit(CollideBall b){
if(!collide){
coll_x=b.getCenterX();
coll_y=b.getCenterY();
collide=true;
public void paint(Graphics gr){
g=gr;
g.setColor(color);
//the coordinates in fillOval have to be int, so we cast
//explicitly from double to int
g.fillOval((int)x,(int)y,diameter,diameter);
//Draws half white and half dark gray arc around the balls to give light and shadow effect
g.setColor(Color.white);
g.drawArc((int)x,(int)y,diameter,diameter,45,180);
g.setColor(Color.darkGray);
g.drawArc((int)x,(int)y,diameter,diameter,225,180);
public class BouncingBalls extends Applet implements Runnable {
Thread runner;
Image Buffer;
Graphics gBuffer;
CollideBall ball[];
//Obstacle o;
//how many balls?
static final int MAX=60;
boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
boolean shiftNW,shiftSW,shiftNE,shiftSE;
int xtemp,ytemp,startx,starty;
int west, north, east, south;
public void init() {
Buffer=createImage(getSize().width,getSize().height);
gBuffer=Buffer.getGraphics();
ball=new CollideBall[MAX];
int w=getSize().width-5;
int h=getSize().height-5;
//our balls have different start coordinates, increment values
//(speed, direction) and colors
for (int i = 0;i<30;i++){
ball=new CollideBall(w,h,48+i,500+i,1.5,2.0,Color.white);
ball[i+30]=new CollideBall(w,h,890+i,200+i,1.5,2.0,Color.red);
public void start(){
if (runner == null) {
runner = new Thread (this);
runner.start();
/* public void stop(){
if (runner != null) {
runner.stop();
runner = null;
public void run(){
while(true) {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
try {runner.sleep(15);}
catch (Exception e) { }
//move our balls around
for(int i=0;i<MAX;i++){
ball[i].move();
handleCollision();
repaint();
boolean collide(CollideBall b1, CollideBall b2){
double wx=b1.getCenterX()-b2.getCenterX();
double wy=b1.getCenterY()-b2.getCenterY();
//we calculate the distance between the centers two
//colliding balls (theorem of Pythagoras)
double distance=Math.sqrt(wx*wx+wy*wy);
if(distance<b1.diameter)
return true;
return false;
private void handleCollision(){
//we iterate through all the balls, checking for collision
for(int i=0;i<MAX;i++)
for(int j=0;j<MAX;j++){
if(i!=j){
if(collide(ball[i], ball[j])){
ball[i].hit(ball[j]);
ball[j].hit(ball[i]);
public void update(Graphics g){
paint(g);
public void paint(Graphics g) {
gBuffer.setColor(Color.lightGray);
gBuffer.fillRect(0,0,getSize().width,getSize().height);
gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
//paint our balls
for(int i=0;i<MAX;i++)
ball[i].paint(gBuffer);
g.drawImage (Buffer,0,0, this);
Thanks againthis.user wrote:
JakeG27 post your code within the code tab it will be more clear.
You can do this by clicking on CODE when you do this will appear { code} { code} post your code inbetween those to tags.
ie
{ code} code... { code}
and it will look like this
code
This must be the first sensible post you've ever made. At least you're able to copy someone else's response and pretend you know something. -
Alarm status drawing iow: recolour JInternalFrame components
Greetings,
Please have a look at this picture. It's a low res snapshot of
a few quite complicated components. Most of the functionality isn't
visible nor relevant in the example. What you're looking at is a real time
process of some sort. Things can go wrong in that process. In a previous
version of my views I'd turn the background colour of some components
red/yellow/green according to the 'alarm status' of the process. One of
my customers suggested the idea of turning everything red/yellow/green
inside those JInternalFrames (that's what you're looking at in the example).
Of course one fool can ask more than a dozen of wise men can answer
and I am not that wise, so my question is: how would one change the
colour of all components that are part of a JInternalFrame (or any
other container) such that the colour wouldn't be 100% opague but
still visible by itself and still showing the information originally present
in each individual component. iow, as if a transparent monochrome
filter were positioned in front of that entire JContainer.
In a naive way I like the idea; if the idea turns out to be too complicated
to realize I'd be happy with visual alternatives also. (such as big arrows
pointing to the JContainer where the alarm happened).
Note that these appliations run in a 'factory' environment where people
either hardly watch the screens or they watch them at quite a great
distance. The changing colours should just attract their attention so they
will walk/run/drive/ride to the screens for a second inspection.
Any ideas are appreciated.
kind regards,
JosNot sure I understand the question, but I keyed in on:
as if a transparent monochrome filter were positioned in front of that entire JContainer.So maybe you could use a GlassPane:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GlassPaneTest extends JFrame
public GlassPaneTest()
final JComponent glassPane = new JComponent()
public void paintComponent(Graphics g)
g.setColor( getBackground() );
g.fillRect(0, 0, getSize().width, getSize().height);
glassPane.setOpaque( false );
glassPane.setBackground( new Color(240, 20, 20, 100) );
setGlassPane( glassPane );
glassPane.addKeyListener( new KeyAdapter()
public void keyPressed(KeyEvent e)
e.consume();
glassPane.addMouseListener( new MouseAdapter()
public void mousePressed(MouseEvent e)
e.consume();
final JButton button = new JButton( "Click Me" );
button.setMnemonic('c');
button.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent e)
glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
glassPane.setVisible( true );
glassPane.requestFocus();
Thread thread = new Thread()
public void run()
try { this.sleep(5000); }
catch (InterruptedException ie) {}
glassPane.setVisible( false );
glassPane.setCursor(null);
thread.start();
getContentPane().add(new JLabel("NORTH"), BorderLayout.NORTH );
getContentPane().add( button );
getContentPane().add(new JTextField(), BorderLayout.SOUTH);
public static void main(String[] args)
GlassPaneTest frame = new GlassPaneTest();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setSize(300, 300);
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html]How to Use Glass Panes shows how you can also do a simple drawing (your arrow?) on the glass pane. -
Looking for a high-res drawing app for the iPad
I've tried a few of the available iPad drawing apps like Sketchbook Pro and Brushes. It's a little hard to tell, because documentation tends to be short on details, but it appears that most of them (with the exception of Brushes) only let you work and export images at 1024 by 768 resolution. That isn't really high enough resolution for professional work.
Brushes is the only exception I've found. You work on the iPad in Brushes at 1024 by 768, but they have this OS X app that can convert your exported images to a higher res.
To me that's crazy awkward and time-consuming, and I think Brushes is OK as a drawing app, but not necessarily what I'm looking for.
Can anyone give me some better insight into the matter?
Is there some underlying technical reason that all of these apps have a hard limit of 1024 by 768 resolution?
Is there an app other than Brushes that can produce pro-level (high resolution) image files on the iPad?
Thanks,
JSYubz Magnum really has great sound. They come in four colors too.
Check out the new remodeled MacOSG website! 24-hour Apple-related news & support.
MacOSG: An Apple User Group iTunes: MacOSG Podcast Follow us on Twitter: MacOSG -
CS5 or Elements for Drawing?
hello everyone. I know this doesn't sound original but I have yet to find an answer so I came here. I am hoping to get a Wacom Bamboo Fun tablet soon and it includes Adobe Elements 8. I am an artist and browsing around places like DeviantArt i find that most digital artists use the program CS5 or something like that. So here's my question: is CS5 or Elements better for drawing? I'm seriously thinking about getting CS5 but i don't want to waste my money if Elements is just as good. Please help me out!!
Elements is more limited in how to adjust the colors to black-and-white.
Lightroom has more sophisticated adjustments. These adjustments are the same as in the Camera Raw plug-in for Photoshop, but absent in the Camera Raw plug-in for Elements. The adjustments allow you to enhance the contrast and brightness of the gray-level for narrow ranges of original colors instead of a simple removal of color with a default color-balance or clicking on a preset that Elements has.
Here is a very verbose video introduction to the LR B/W conversion on an example photo, viewed best in full-screen HD:
http://www.luminous-landscape.com/tutorials/bw_workflow_in_lightroom.shtml
Here is a step-by-step example with screenshots and description, from 2008, but the adjustments still mostly apply, except the vignetting you’d use wouldn’t be lens-related, it’d be the Post-Crop Vignetting in the Effects section that didn’t exist back in 2008:
http://layersmagazine.com/create-stunning-black-and-white-images-in-lightroom.html
These were just the first and third links that showed up after Googling for Lightroom Black and White.
BTW, I am a photo-hobbyist and use Lightroom every day, so it’s not just for professionals making money off their photos that need something fast. For me it is more about seriousness and perfection and freedom. -
Error message (Because a USB device was drawing too much power)
Hi Everyone,
Bought recently a new macbook pro 13 inch with Retina display with 120 GB flash drive.
Connected a non-apple CD drive to my macbook and after that started receiving this message: "Because a USB device was drawing too much power from your computer, one or more of your USB devices have been disabled."
initially I was receiving this message after I switch on my macbook but now after every 30 seconds this message pops up although I never connected anything to my macbook through its USB ports.
Will highly appreciate for your help on how to get rid of this problem.
Regards
HomayunTry resetting the SMC
Shut down the computer.
Plug in the MagSafe power adapter to a power source, connecting it to the Mac if its not already connected.
On the built-in keyboard, press the (left side) Shift-Control-Option keys and the power button at the same time.
Release all the keys and the power button at the same time.
Press the power button to turn on the computer.
Note: The LED on the MagSafe power adapter may change states or temporarily turn off when you reset the SMC. -
When I try to print a drawing imported from my ipad iphoto crops it. Is there any way to stop this?
Usual cause: printing at the wrong aspect ratio for the image - trying to print 5 x 3 in the shape of a 6 x 4 for instance.
Regards
TD -
Draw back of Automatic PO creation
Dear Friends,
What are all the draw backs will come if i cxreate PO automatically once GR posted.
Kindly explain me.
Rgds,
Sankar.DPrerequisits.
a) Movement type has to be selected for automatic creation of PO in customizing (IM - GR - Create PO automatically)
b)Assign Std. Purchasing Org. to plant (Enterprise structure - Assignment - MM)
c)Define default values for PO document type depending on T-Code MB01
d)Material should be valuated material with material master
e)Valid price should be there in Purchasing Info. record.
There are no drawbacks as such , but you can only procure valuated materials, PO of consumable materials is ruled out .
Check the possibilities and let us know what is your specific requirement.
Regards -
Photoshop CC: When I'm trying to draw a rectangle I can't fill it or create a stoke because there is a message telling me; "Could not complete your request because of a program error. What can I do?
It is a mute point now. PSE12 finally failed to the point it locked up the MAC. I had to restore the MAC OS from backup to a point before the PSE12 update.
The MAC now operates correctly and so does PSE12. I don't think I'll be updating PSE any time soon. -
Can not use all the tools in my drawing markups any ideas on getting them to work?
Can not use all the tools in my drawing markups any ideas on getting them to work?
Hi tonys60181,
Could you please let me know what version of Adobe Acrobat are you using.
What all drawing tools are you unable to access?
Is this issue specific to one PDF file or all?
What exactly happens when you try to use any drawing markup?
Please let me know.
Regards,
Anubha -
Use DPM to backup Exchange DAG can not see the database
Hi,
I want to use DPM to backup Exchange DAG, but when I create the protection group, I can't open the dag to choose the database.
If somebody can tell me what's wrong with it? How to troubleshoot this problem?
The version of DPM is 2012 sp1,and the version of Exchange is 2013.
I'm sorry that I could just provide a picture in Chinese.
I received this event on the DPM Server:
Log Name: System
Source: Microsoft-Windows-DistributedCOM
Event ID: 10016
Description:
The application-specific permission settings do not grant Remote Launch permission for the COM Server application with CLSID {CC7D8A18-C386-48D5-9906-4FFC77A39788} to the user DOMAIN\DC$ SID (S-1-5-21-3005733532-2211877466-3700573520-15394).
This security permission can be modified using the Component Services administrative tool.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-DistributedCOM" Guid="{1B562E86-B7AA-4131-BADC-B6F3A001407E}" EventSourceName="DCOM" />
<EventID Qualifiers="0">10016</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x8080000000000000</Keywords>
<TimeCreated SystemTime="2014-04-08T08:25:20.222501400Z" />
<EventRecordID>2715</EventRecordID>
<Correlation />
<Execution ProcessID="856" ThreadID="2380" />
<Channel>System</Channel>
<Computer>DPMSERVER.domain.local</Computer>
<Security UserID="S-1-5-21-3005733532-2211877466-3700573520-15394" />
</System>
<EventData>
<Data Name="param1">application-specific</Data>
<Data Name="param2">Remote</Data>
<Data Name="param3">Launch</Data>
<Data Name="param4">{CC7D8A18-C386-48D5-9906-4FFC77A39788}</Data>
<Data Name="param5">{A3B9D3F4-2477-4F95-B2D1-F75B0FDF2A0E}</Data>
<Data Name="param6">DOMAIN</Data>
<Data Name="param7">DC$</Data>
<Data Name="param8">S-1-5-21-3005733532-2211877466-3700573520-15394</Data>
<Data Name="param9">172.16.103.3</Data>
<Data Name="param10">Unavailable</Data>
<Data Name="param11">Unavailable</Data>
</EventData>
</Event>
Kindly clarify me, Thanks in advance.
thorneHi,
please take a look at this:
http://social.technet.microsoft.com/Forums/en-US/0d876796-cef4-4ec4-a76e-dcda8c0bcea8/dpm-2012-sp1-protecting-exchange-2010-and-exchange-2013-at-the-same-time?forum=dpmexchbackup
regards
/bkpfast
My postings are provided "AS IS" with no warranties and confer no rights -
I am trying to upload photos from my digital camera. Every time I try to plug it into my USB, the following error message comes up: "Because a usb device was drawing too much power from your computer, one or more of your USB devices have been disabled."
I don't have anything else plugged into my MBP, so I am confused as to what's going on. This problem has never happened before. MBP is less than a year old - about 9 months old. HELPGet a powered USB hub.
https://discussions.apple.com/community/notebooks/macbook_pro?view=documents -
Can I draw *.bmp, *.png in java.awt.canvas ?
In paint method of my program, I get image from Toolkit like this:
public class CanCanvas extends Canvas{
//In loadImage method
Toolkit.getDefaultToolkit().getImage(
getClass().getClassLoader().getResource(
resource.getString("bg.jpg")));
//.... In paint method
if (image != null && image.size() > 0) {
for (int j = 0; j < image.size(); j++) {
Image image1 = (Image) image.elementAt(j);
Rectangle rectangle = (Rectangle) imgLocation.elementAt(j);
g.drawImage(image1, rectangle.x, offset + rectangle.y,
rectangle.width, rectangle.height, null);
i = i <= rectangle.y + rectangle.height + 7 ? rectangle.y
+ rectangle.height + 7 : i;But there is something very strange, if my image is *.jpg or *.gif, it runs ok, otherwise -*.bmp, *.png-, it can't draw the image.
Would anyone tell me why ? Is the reason java.awt.canvas ?
Thanks in advance ^ ^If you'd bother to read the documentation of the methods you're using, you'd know:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)
Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG.
Maybe you are looking for
-
The Quicktime manual indicates that .pdf is an acceptable format, however I can't open a pdf file in Quicktime. Any suggestions?
-
How do you avoid your class to be cloned?
Hi All, Can any one let me know how to avoid my class being cloned?and the scenarios where we need to implement this feature. Thanks in advance, venu.
-
Hi, I have an xml which has some target namespace. I need to remove the namespace and the qualifiers and put it on a machine using a file adapter. Any help in this regard is highly appreciated. With Regards, Harsh
-
Do you use the e-mail APIs in Oracle 9iFS?
Have you built an application that uses the Oracle 9iFS e-mail APIs? * oracle.ifs.adk.user package classes? * oracle.ifs.adk.mail package classes? * EmailUserProfile? If so, we would like to learn more about your requirements. Please contact me at [e
-
I've had a problem with downloading movies from iTunes
I have been downloading a tv series (firefly) from the iTunes store. For the last four downloads I've done were automatically repeated after completing before I could watch them. I have a slow Internet and each video is around 500kb witch for me take