MouseOver in Drawing
I am making a program that basically draws circles with lines connecting them. When I run my mouse over one of the circles I want some text to be displayed.
How do I do this?
I know that ToolTip is available for buttons, can it work for drawings too? If so then how?
Also, it would be great if when a person moused over one of the circles the circles illuminated. (Grew in size.) How do you do this.
Also this is an applet
Thanks
-Nick
Edited by: paradox_qu on Nov 27, 2007 1:49 AM
One approach I can think of (untested)
-- create an array or ArrayList of Ellipse2D.Double to store your circles.
-- In a MouseMotionListener (or MouseMotionAdapter) mouseMoved () event, iterate over the collection and detect whether any Ellipse2D.Double contains (...) the mouse coordinates.
-- if there can be multiple contains (...) that is, your circles overlap, you'll need to code for that.
-- set instance field values that are used by the paint (...) override (awt) or paintComponent (...) override (swing) and drawString (...) the text (and any other graphics work).
For a ToolTip, I think it should work to setToolTipText on the JComponent... if this is awt you might have to code it rigorously.
Luck, db
Similar Messages
-
How do i stop draw refresh on mouseover?
I am drawing shapes on a custom element, and running a function on draw. for somereason it is constantly redrawing anytime I mouse over the shape how can I stop that?I am using cs6. here is a sample code with the issue that I am talking about was taken from a photoshop scripting forum but illustrtates my point. everytime you mouseover or mouseout the square it initiates the on draw but i only want it to redraw on the press of a button.
var winRes = "dialog { \
text: 'ScriptUI Graphics test', \
margins: 15, \
alignChildren: 'row', \
canvas: Custom { \
preferredSize: [200, 200], \
creation_properties: {borderStyle: 'black'} , \
buttonsGroup: Group{ \
cancelButton: Button { text: 'Cancel', properties:{name:'cancel'} }, \
tryButton: Button { text: 'Try', properties:{name:'try'},size: [40,24], alignment:['right', 'center'] }, \
// Window
var win = new Window(winRes);
function color() { return [Math.random(),Math.random(),Math.random(),1] }
// define the graphic property
canvasGraphics = win.canvas.graphics
// do the drawing
win.canvas.onDraw = redraw
function redraw() {
// creates a red filled square
canvasGraphics.newPath()
canvasGraphics.rectPath(10, 10, 200, 200)
canvasGraphics.fillPath(canvasGraphics.newBrush(canvasGraphics.BrushType.SOLID_COLOR, color(), 1)) // HERE
win.buttonsGroup.tryButton.onClick = function() {
win.canvas.notify("onDraw")
win.show()This appears to be a bug that has been fixed in AECC. I tried it in CS6 and the color box flickers like mad when you mouseover it and also changes when clicking the button. In AECC it appears to be working properly and is not effected by mousing over the box.
-
How to detect mouseover of line drawing
I have a series of lines that I draw onto my canvas. I would
like to be able to detect the mouseover for the specific line then
based on the line show certain information. I can create a
mouseover for a button or object, but am unsure of how to do this
for a specific line being drawn on the canvas. Any direction would
be great, Thanks!I was drawing the line and assigning it to a MovieClip.
The code in Flash 8 for the function that does that is:
drawLines = function():Void{
myColor = this.color_ = 0x000000;
myLine = this.linea = 5;
if(origin) {
x1 = Canvas._xmouse;
y1 = Canvas._ymouse;
origin = !origin;
msg.text ="Move and click the mouse where you want to end
the line";
msgFormat();
} else{
x2 = Canvas._xmouse;
y2 = Canvas._ymouse;
Canvas.createEmptyMovieClip("line"+nLines,Canvas.getNextHighestDepth());
Canvas["line"+nLines].lineStyle (myLine, myColor, 100);
Canvas["line"+nLines].moveTo (x1,y1);
Canvas["line"+nLines].lineTo (x2,y2);
Canvas["line"+nLines].p1 = {x:x1, y:y1};
Canvas["line"+nLines].p2 = {x:x2, y:y2};
gsbTrace("p1= "+Canvas["line"+nLines].p1.x +" p2=
"+Canvas["line"+nLines].p2.x);
drawing = false;
msg.text ="To draw another line, click on 'Draw Routes'
again\n\nTo delete the line click on it and then on 'Delete
Selected Object'";
msgFormat();
nLines ++;
for(var sInstance:String in Canvas) {
Canvas[sInstance].onPress = function():Void {
mSelected = null;
lSelected = this;
l_selected.text = lSelected._name;
index = lSelected._name.substr(1);
var myColor:Number = 0xFF0000;
lSelected.clear();
lSelected.lineStyle (5, myColor, 100);
lSelected.moveTo (lSelected.p1.x,lSelected.p1.y);
lSelected.lineTo (lSelected.p2.x,lSelected.p2.y);
myDragger._visible = false;
gsbTrace("lSelected... "+ lSelected);
In Flex, instead of creating the line in a MovieClip, you can
put it on a sprite (basically a component) using the addChild
method.
I hope this helps.
Gilbert -
I have a graphic floor plan with 4 apartments. I want to
create a mouseover effect whereby when the mouse moves over each
apartment, the respective turns blue leaving the other 3 white. I
have created five jpegs, one all white and the other four tinted
blue respectively. How do I create this effect using these five
jpegs?I assume you may want to see the floor plan and furnature
arrangements under the blue and white.
If so you can create buttons the shape of the
apartments/rooms. In the rollover frame draw a graphic the shape of
the room fill it with solid blue. Make it into a graphic or movie
clip. Apply the alpha to allow you to see through it. F^ on frame 4
of the buttonto duplicate shape to hit area of button.
Do this for each appartment/room.
When you mouse over the apartment/room it will be highlighted
with blue. when you roll out itwill return to normal.
Hope I understood you correctly. Hope it helps. -
Drawing problems in Minefield interface elements and page content
Some sort of graphic related problem with Minefield nightly builds.
I'm not an expert, but it looks like the problem is with semi transparent pixel drawing. Might this be related with graphics hardware?
Here is the screenshot, how it looks:
http://img148.imageshack.us/img148/2536/ffinterface1.png
In the picture the problem is well seen on the TAB headers and vertical line with a pattern in a page illustrates the problem in displaying transparent elements in page content.
When interactive interface elements are mouseovered (paticularly "close tab" buton), the distortion around changes.Try the Builds forum over at MozillaZine, that's where all the "testers" hang out.
http://forums.mozillazine.org/viewforum.php?f=23 -
Overlapping elements mouseover DrawState
Hi guys!
Soo I'm really desperate and some hints or solution would be really appreciated!
I'm building custom framework for more than a year now that have some classes handling UI elements, since I want to draw elements exactly as I want. I've managed to make some goodies as drawing dashed lines, stack multiple images to build a skin with single element, but I have problems with the event handling.
I came to conclusion that you can override Group element behavior and design it quite nice, but at the moment you add custom .onDraw function, the group stops to receive MouseEvent-s, except in the Bubbling phase from a child element.
Best scenario:
Group 2 has images, borders and so on (custom onDraw) + receives mouse events (mouseover, mouseout, click) - simulates button element, but can have child elements. In this case Group 3 and 4 are children of Group 2 and Group 2 is child of Group 1:
Group 1
Group 2Group 3
Group 4
Closest so far:
Group 3 and Group 4 are children of Group 2. Group 2 and Button 1 are children of Group 1.
Group 1Button 1
Group 2Group 3
Group 4
The problem:
Button 1 does not receive "mouseover" when the mouse is over the Group 2 area. And because Group 2 is not child of Button 1, Button 1 can't have .addEventListener( 'mouseover', handlerFunction, false ) for the bubbling phase.
My workaround and the new problem:
I've decided to simulate "mouseover" event and update the onDraw method of Button 1 using the notify method of the element, but the onDraw method's DrawState always has mouseOver = false no matter what!
Simple code:
buttonOne.onDraw = function( /*DrawState*/ $drawState ){
$.writeln( $drawState.mouseOver ) // always false except if the mouse is really over the button
function buttonOneMouseover( /*MouseEvent*/ $e ){
$e.target.notify( 'onDraw' );
function simulateButtonOver( /*MouseEvent*/ $e ){
var fakeMouseEvent = ScriptUI.events.createEvent('MouseEvent');
fakeMouseEvent.initMouseEvent( "mouseover", true, true, $e.target.parent.buttonOne, 1, $e.target.window.location[0]+5, $e.target.window.location[1]+5, 1, 1, undefined, undefined, undefined, -1 );
$e.target.parent.buttonOne.dispatchEvent( fakeMouseEvent );
groupTwo.addEventListener( 'mouseover', simulateButtonOver, false );
buttonOne.addEventListener( 'mouseover', buttonOneMouseover, false );
Any help is REALLY appreciated!
Cheers,
TonyOK I've managed to hack another solution. I've added customDrawState and removeDrawState methods to my element's controller. They take as argument basic object that must override the original DrawState object that the element receives onDraw( /*DrawState*/ $drawState ). In my case the .mouseOver property of the DrawState object. Also dispatching custom event is useless if you override the draw state so calling the element's notify('onDraw') works like a charm. Beware that Custom elements do not have .relatedTarget for the MouseEvent object if you use addEventListener('mouseover') for instance. You have to use Button class instead in your UI.
-
Creating hiding drawer component (suggestions)
I am attempting to create a hiding drawer component. This is basically a tabbed frame on the side of the container that will allow you to show and hide it. I am able to get the component to show up but the catch is I need to know how to add components such as JList etc.. to it and have them function properly. When I attempt to add a component to it the painting is not working properly. I'm currently extending JPanel should I be using something else? Thanks for the help guys.
Code is below:
package com.nashilnux.swing;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Composite;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.RepaintManager;
import javax.swing.text.AbstractDocument.Content;
* @author me
public class HidingDrawer extends JPanel
Rectangle2D button = null;
private boolean showing = false;
private JList contentList = null;
private String title = "";
private boolean mouseOver = false;
private JScrollPane listSP = null;
private Color strokeColor = new Color(226, 242, 255);
private Color backgroundColor = Color.white;
private Color tabColor = new Color(226, 242, 255);
private boolean transparent = false;
private float transparencyLevel = 0.0f;
private Dimension expandedDimension = new Dimension(300,200);
public HidingDrawer()
setOpaque(false);
setPreferredSize(new Dimension(300, 200));
addMouseListener(new MouseAdapter()
@Override
public void mousePressed(MouseEvent e)
hideDrawer(e);
public HidingDrawer(boolean showDrawer)
setOpaque(false);
setPreferredSize(new Dimension(300, 200));
setLayout(new FlowLayout());
if (showDrawer)
showing = false;
else
showing = true;
addMouseListener(new MouseAdapter()
@Override
public void mousePressed(MouseEvent e)
hideDrawer(e);
@Override
public void mouseEntered(MouseEvent e)
if (button != null)
if (button.contains(new Point2D.Double(e.getX(), e.getY())))
System.out.println("Mouse Over");
mouseOver = true;
repaint();
@Override
public void mouseExited(MouseEvent e)
System.out.println("Mouse exited");
mouseOver = false;
repaint();
initalize();
* @param args
public static void main(String[] args)
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.LIGHT_GRAY);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("UI Drawer Demo");
// North Panel
JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
northPanel.setBackground(Color.white);
JLabel titleLbl = new JLabel("UI Drawer Demo");
titleLbl.setFont(new Font("Helvectia", Font.BOLD, 18));
northPanel.add(titleLbl);
// End NorthPanel
// West panel component
HidingDrawer hd = new HidingDrawer(true);
hd.setTitle("Testing");
hd.setBackgroundColor(new Color(226, 242, 255));
hd.setStrokeColor(Color.black);
hd.setTransparent(true);
hd.setTransparencyLevel(0.5f);
frame.getContentPane().setBackground(hd.getBackgroundColor());
// Add list to the drawer
// String[] values = new String[]{"Testing", "Testing 2", "Testing 3"};
// JList list = new JList(values);
// hd.add(list, BorderLayout.CENTER);
frame.getContentPane().add(hd, BorderLayout.WEST);
// Center Panel
JPanel encapPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
encapPanel.setBackground(hd.getBackgroundColor());
JPanel centerPanel = new JPanel();
centerPanel.setBackground(hd.getBackgroundColor());
GridBagLayout gLayout = new GridBagLayout();
int row = 0;
centerPanel.setLayout(gLayout);
GridBagConstraints c = new GridBagConstraints(0, 0,1,1,0, 0,GridBagConstraints.WEST,0, new Insets(5,5,5,5),0,0);
JLabel freqLbl = new JLabel("Frequency");
centerPanel.add(freqLbl, c);
c.gridx = 1;
JTextField freqTxt = new JTextField(20);
centerPanel.add(freqTxt, c);
encapPanel.add(centerPanel);
frame.getContentPane().add(northPanel, BorderLayout.NORTH);
frame.getContentPane().add(encapPanel, BorderLayout.CENTER);
frame.setSize(new Dimension(800, 600));
frame.setVisible(true);
public void initalize()
// String[] tmpListItems = { "Testing list item 1", "Testing 2", "Testing 3" };
// contentList = new JList(tmpListItems);
// contentList.setOpaque(true);
// contentList.setBackground(getBackgroundColor());
// Dimension dim = getPreferredSize();
// dim.setSize(dim.getWidth() - 70, dim.getHeight());
// listSP = new JScrollPane(contentList);
// listSP.setPreferredSize(dim);
// listSP.setOpaque(true);
// listSP.setBackground(getBackgroundColor());
// add(listSP);
setBackground(getBackgroundColor());
setBorder(BorderFactory.createLineBorder(Color.black));
* (non-Javadoc)
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
@Override
protected void paintComponent(Graphics g)
Dimension dim = getSize();
Graphics2D g2d = (Graphics2D) g;
if (!isShowing())
System.out.println("Showing: " + showing);
g2d.setPaint(getBackgroundColor());
RoundRectangle2D roundRectangle = new RoundRectangle2D.Double(getX() - 10, getY() + 5, dim.width - 20, dim.height - 10, 5, 15);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if(isTransparent())
Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTransparencyLevel());
g2d.setComposite(alphaComp);
g2d.fill(roundRectangle);
BasicStroke stroke = new BasicStroke(3);
g2d.setStroke(stroke);
g2d.setPaint(getStrokeColor());
g2d.draw(roundRectangle);
// Draw a fake button
// Get the dimension of the current graphic
Graphics2D buttonArea = (Graphics2D) g2d.create(getX(), getY(), dim.width, dim.height);
buttonArea.setColor(getTabColor());
buttonArea.setFont(new Font("Helvetica", Font.BOLD, 16));
button = null;
button = new Rectangle2D.Double(roundRectangle.getBounds().getMaxX(), (roundRectangle.getMaxY() / 2) - 30, 25, 60);
buttonArea.fill(button);
buttonArea.draw(button);
// Draw the text
buttonArea.setStroke(new BasicStroke(3));
buttonArea.setPaint(getStrokeColor());
buttonArea.draw(button);
buttonArea.setClip(button);
buttonArea.setPaint(Color.black);
AffineTransform transformer = buttonArea.getTransform();
transformer.rotate(Math.toRadians(90));
buttonArea.transform(transformer);
Rectangle2D buttonBounds = button.getBounds2D();
Font buttonFont = new Font("Helvectica", Font.BOLD, 18);
FontRenderContext frc = buttonArea.getFontRenderContext();
TextLayout layout = new TextLayout("Hide", buttonFont, frc);
layout.draw(buttonArea, (float)buttonBounds.getY() + 10,(float)((buttonBounds.getX() - (buttonBounds.getX() *2)) -5));
else
System.out.println("Showing: " + showing);
Graphics2D buttonArea = (Graphics2D) g2d.create(getX(), getY(), dim.width, dim.height);
buttonArea.setPaint(getTabColor());
button = null;
button = new Rectangle2D.Double(0, (dim.getHeight() / 2) - 30, 25, 60);
if (isTransparent())
// Set the Composite
Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTransparencyLevel());
buttonArea.setComposite(alphaComp);
buttonArea.fill(button);
buttonArea.setStroke(new BasicStroke(3));
buttonArea.setPaint(getStrokeColor());
buttonArea.draw(button);
super.paintComponents(g);
public void hideDrawer(MouseEvent event)
if (button != null)
if (button.contains(new Point2D.Double(event.getX(), event.getY())))
System.out.println("Button Pressed");
if (showing)
showing = false;
setPreferredSize(new Dimension(300, getSize().height));
setSize(new Dimension(300, getSize().height));
setVisible(true);
// Hide the list
// contentList.setVisible(true);
// listSP.setVisible(true);
else
showing = true;
setSize(28, getSize().height);
// contentList.setVisible(false);
// listSP.setVisible(false);
Object parent = getParent();
boolean foundParent = false;
while (!foundParent)
Component parentsChild = (Component) parent;
Component fParent = ((Component) parent).getParent();
if (fParent == null)
foundParent = true;
parent = parentsChild;
else
parent = fParent;
Component pComponent = (Component) parent;
pComponent.repaint();
* @param showing
* the showing to set
public void showDrawer(boolean showing)
this.showing = showing;
* @return the showing
public boolean isShowing()
return showing;
* @param title
* the title to set
public void setTitle(String title)
this.title = title;
* @return the title
public String getTitle()
return title;
* @param strokeColor
* the strokeColor to set
public void setStrokeColor(Color strokeColor)
this.strokeColor = strokeColor;
* @return the strokeColor
public Color getStrokeColor()
return strokeColor;
* @param backgroundColor
* the backgroundColor to set
public void setBackgroundColor(Color backgroundColor)
this.backgroundColor = backgroundColor;
* @return the backgroundColor
public Color getBackgroundColor()
return backgroundColor;
* @param tabColor
* the tabColor to set
public void setTabColor(Color tabColor)
this.tabColor = tabColor;
* @return the tabColor
public Color getTabColor()
return tabColor;
* @param transparent the transparent to set
public void setTransparent(boolean transparent)
this.transparent = transparent;
* @return the transparent
public boolean isTransparent()
return transparent;
* @param transparencyLevel the transparencyLevel to set
public void setTransparencyLevel(float transparencyLevel)
this.transparencyLevel = transparencyLevel;
* @return the transparencyLevel
public float getTransparencyLevel()
return transparencyLevel;
}import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;
public class HD {
TopCard topCard;
HostCard hostCard;
CardLayout cards;
JPanel cardPanel;
private JPanel getContent() {
Color stroke = UIManager.getColor("TabbedPane.foreground");
Color bg = UIManager.getColor("TabbedPane.background");
Color tab = UIManager.getColor("TabbedPane.contentAreaColor");
Font font = //new Font("Helvetica", Font.BOLD, 18);
new Font("Dialog", Font.BOLD, 18); // faster
Dimension d = new Dimension(300,200);
topCard = new TopCard(stroke, bg, tab, font, d);
topCard.addMouseListener(mouser);
hostCard = new HostCard(stroke, bg, tab, font, d);
hostCard.addMouseListener(mouser);
addComponents(hostCard);
cards = new CardLayout();
cardPanel = new JPanel(cards);
cardPanel.add("top", topCard);
cardPanel.add("host", hostCard);
return cardPanel;
private void addComponents(JComponent c) {
String[] tmpListItems = { "Testing list item 1", "Testing 2", "Testing 3" };
JList list = new JList(tmpListItems);
int vm = hostCard.MARGIN;
int right = 35;
Dimension dim = c.getPreferredSize();
dim.setSize(dim.width - 70, dim.height - 2*vm - 2*20);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(dim);
c.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(vm,0,vm,right);
c.add(scrollPane, gbc);
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new HD().getContent());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
private MouseListener mouser = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Object source = e.getSource();
Point p = e.getPoint();
if(source == topCard)
if(topCard.isControlTrigger(p))
cards.next(cardPanel);
if(source == hostCard)
if(hostCard.isControlTrigger(p))
cards.next(cardPanel);
class TopCard extends JPanel {
Rectangle2D.Double rect;
Color strokeColor;
Color backgroundColor;
Color tabColor;
Font font;
public TopCard(Color stroke, Color bg, Color tab, Font f, Dimension d) {
strokeColor = stroke;
backgroundColor = bg;
tabColor = tab;
font = f;
setPreferredSize(d);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Dimension dim = getSize();
g2.setPaint(Color.lightGray);
g2.fillRect(0, 0, dim.width, dim.height);
g2.setPaint(tabColor);
rect = new Rectangle2D.Double(0, (dim.getHeight() / 2) - 30, 25, 60);
g2.fill(rect);
g2.setStroke(new BasicStroke(3));
g2.setPaint(strokeColor);
g2.draw(rect);
// Draw label text.
String s = "Show";
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
float width = (float)font.getStringBounds(s, frc).getWidth();
LineMetrics lm = font.getLineMetrics(s, frc);
float height = lm.getAscent() + lm.getDescent();
double x = rect.getCenterX() - height/2 + lm.getDescent();
double y = rect.getCenterY() - width/2;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.PI/2, 0, 0);
g2.setFont(font.deriveFont(at));
g2.drawString(s, 0, 0);
public boolean isControlTrigger(Point p) {
return rect.contains(p);
class HostCard extends JPanel {
Rectangle2D.Double rect;
Color strokeColor;
Color backgroundColor;
Color tabColor;
Font font;
int MARGIN = 5;
public HostCard(Color stroke, Color bg, Color tab, Font f, Dimension d) {
strokeColor = stroke;
backgroundColor = bg;
tabColor = tab;
font = f;
setPreferredSize(d);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Dimension dim = getSize();
g2.setPaint(Color.lightGray);
g2.fillRect(0, 0, dim.width, dim.height);
BasicStroke stroke = new BasicStroke(3);
float lineWidth = stroke.getLineWidth();
double x = getX() - MARGIN - lineWidth;
double y = getY() + MARGIN;
double w = dim.width - 20;
double h = dim.height - 2*MARGIN - lineWidth/2;
RoundRectangle2D roundRectangle =
new RoundRectangle2D.Double(x, y, w, h, 5, 15);
g2.setPaint(backgroundColor);
g2.fill(roundRectangle);
g2.setStroke(stroke);
g2.setPaint(strokeColor);
g2.draw(roundRectangle);
rect = new Rectangle2D.Double(roundRectangle.getBounds().getMaxX(),
(roundRectangle.getMaxY() / 2) - 30, 25, 60);
g2.setPaint(tabColor);
g2.fill(rect);
g2.setPaint(strokeColor);
g2.draw(rect);
g2.setPaint(Color.black);
// Draw label text.
String s = "Hide";
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
float width = (float)font.getStringBounds(s, frc).getWidth();
LineMetrics lm = font.getLineMetrics(s, frc);
float height = lm.getAscent() + lm.getDescent();
x = rect.getCenterX() - height/2 + lm.getDescent();
y = rect.getCenterY() - width/2;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.PI/2, 0, 0);
g2.setFont(font.deriveFont(at));
g2.drawString(s, 0, 0);
public boolean isControlTrigger(Point p) {
return rect.contains(p);
} -
Problem in drawing line in script tag of mxml file
hai i am new in flex .i was trying to draw line in mxml(using mxml ) and did it.
then i try this in actionscript by making as file and shape class object again did it
but
when i put that specific function in <fx:script> tag of mxml file and call it by mouseover method it is not drawing a line.i am sure that on mouse over function was called .but dont know why line is nort draw here.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import flash.display.Shape;
var s:Shape = new Shape();
public function myMain():void
// Launch your application by right clicking within this class and select: Deubg As > FDT SWF Application
so.text="button is cliked";
s.graphics.lineStyle(3, 0x00FF00,.5);
s.graphics.lineTo(200, 200);
this.addChild(s);
so.text="button is cliked";
]]>
</fx:Script>
<mx:Label alpha=".3" id="so" mouseOver="myMain()" text="Button"/>
</s:Application>
Can anyone tell me where i am going wrong.It's a good idea to run you code in the debugger because you will be notified of runtime exceptions that the release version of the Flash Player will not show you. Here's the runtime error I got when running your example:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
atspark.components.supportClasses::SkinnableComponent/addChild()[frameworks\projects\ spark\src\spark\components\supportClasses\SkinnableComponent.as:1118]
at myMain()[b.mxml:19]
at __so_mouseOver()[b.mxml:27]
The problem with your app is it is calling addChild(), which is not supported on s:Application. You need to call addElement() instead. addElement() only takes an object of type IVisualElement so you need to make your shape a UIComponent. Try this:
import mx.core.UIComponent;
private var s:UIComponent = new UIComponent();
public function myMain():void
// Launch your application by right clicking within this class and select: Deubg As > FDT SWF Application
so.text="button is cliked";
s.graphics.lineStyle(3, 0x00FF00,.5);
s.graphics.lineTo(200, 200);
this.addElement(s);
so.text="button is cliked";
-Darrell -
Curious re-drawing of waveforms
I was working with Logic and Soundtrack Pro simultanously today. I noticed that Logic started to re-draw the waveforms everytime I switched back from SP.
So I quit SP and restarted Logic. Same thing still happening. I believe I´ve read somewhere in the forum about this, but can´t find it now.
Any explaination why Logic is doing this constant re-drawing? Any help appreciated!
/juhaniI don't think it's my tablet as the path that gets drawn is accurate. Have you had problems with the path not getting re-drawn, but the new one added to the old one?
Here's an example (drawn with a mouse on another computer)
A quick pencil tool path
Trying to reshape, drawing clockwise. I think we can agree that I was close enough on the ends.
Now drawing the path AGAIN from the other direction.
Now if I'm supposed to be drawing a certain direction when reshaping, shouldn't there be some indicator (like an arrow on mouseover, say) how I should draw it?
If drawing direction isn't the issue, then what is?
I'm willing to work the way the tool wants me to but if the official line is "unexpected results may occur"...that really isn't helpful. -
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.
Maybe you are looking for
-
Saving with filewriter; no data written to file and exceptions
I have tried dealing with the exceptions for this by myself. I cant get rid of my null pointer exception and i think i got lost. Also, as it stands, a file gets saved but no data gets saved to that file. I know i shouldnt use a try and catch method f
-
Microsoft Word Templates in Foreign Language
I just bought Microsoft Office 2008 for my Macbook (with Leopard) and I was looking at the Project Gallery templates and if I open up any of the templates for Microsoft Word, all of the words are in different languages and I cannot even look at the t
-
I just experienced a problem with our CUCM 6.1.2 All my phones went dead suddenly. Internal calls could be made without issue, however outgoing calls received long dead space followed by a busy signal. The real kicker was incoming calls. Incoming cal
-
Disconnections cured by making a phone call
I have what I gather is a strange situation - I have very frequent broadband drop outs but if I make or receive a phone call the broadband comes back up - sometimes for just for a few minutes, sometimes for hours. I have had an engineer visit but it
-
Hi, I have a MBP and I am running out of memory because I have a quite large iPhoto Library (more than 200 GB). I was thinking in moving the library to an airport time capsule in order to have iPhoto acces in my MBP via WIFI to this hard disk. Is tha