How to draw a line after i load a frame?
its simple to draw a line before i load the frame..
when i try to draw a line after i load the frame, i get a error in the last line of the lauchFrame method..
the error is "java.awt.Graphics is abstract; cannot be instantiated"
import java.awt.*;
class GraphArea extends Panel
public void paint(Graphics g)
g.setColor(Color.BLUE);
g.drawLine(0,0,250,250);
public void paint(Graphics g,int X1, int X2)
g.drawLine(0,0,X1,X2);
class Grapherv1 {
private Frame f;
private GraphArea drawPanel;
public Grapherv1() {
f = new Frame("Drawing Shapes:Lenin");
drawPanel = new GraphArea();
public void launchFrame() {
f.setLayout(new FlowLayout());
drawPanel.setSize(950,550);
drawPanel.setBackground(new Color(220,220,220));
drawPanel.setLayout(null);
f.setBackground(Color.white);
f.add(drawPanel);
f.pack();
f.setSize(1000, 800);
f.setVisible(true);
drawPanel.paint(new Graphics(),100,100);
public static void main(String args[]) throws InterruptedException {
Grapherv1 gui = new Grapherv1();
gui.launchFrame();
}please tell me how to call this method ...
public void paint(Graphics g,int X1, int X2)
what argument i should pass for Graphics??
Edited by: Tall-Dude on Dec 3, 2007 4:33 PM
Edited by: Tall-Dude on Dec 3, 2007 4:33 PM
Tall-Dude wrote:
please tell me how to call this method ...
public void paint(Graphics g,int X1, int X2)just past the new x1 and x2 and repaint no need to pass the graphics.
e.g.
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class Grapherv1 {
private Frame f;
private GraphArea drawPanel;
public Grapherv1() {
f = new Frame("Drawing Shapes:Lenin");
drawPanel = new GraphArea();
public void launchFrame() {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
f.setLayout(new BorderLayout());
drawPanel.setSize(950,550);
drawPanel.setBackground(new Color(220,220,220));
drawPanel.setLayout(null);
f.setBackground(Color.white);
f.add(drawPanel);
f.pack();
f.setSize(1000, 800);
f.setVisible(true);
drawPanel.redraw(300,400);
public static void main(String args[]) throws InterruptedException {
Grapherv1 gui = new Grapherv1();
gui.launchFrame();
class GraphArea extends Panel {
int x1, x2;
public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.drawLine(0,0,x1,x2);
public void redraw(int X1, int X2) {
x1 = X1;
x2 = X2;
repaint();
}
Similar Messages
-
How to draw horizontal line in smartform after end of the all line items
Hi Friends,
I am working on the smartform. I have created TABLE node in Main window.
i want to draw a horizontal line after end of the main window table node. i mean after printing all the line items of the table, I need to print one horizontal line.
Could you please help me how to resolve this issue.
FYI: I tried with the below two options. But no use.
1. desinged footer area in the table node of the main window.
2. tried with uline and system symbols.
please correct me if i am wrong. please explain in detail how to draw horizontal line after end of the main window table.
this is very urgent.
Thanks in advance
Regards
RaghuHello Valter Oliveira,
Thanks for your answer. But I need some more detail about blank line text. i.e thrid point.
Could you please tell me how to insert blank line text.
1 - in your table, create a line type with only one column, with the same width of the table
2 - in table painter, create a line under the line type
3 - insert a blank line text in the footer section with the line type you have created. -
Hi All,
I want to draw a line after zooming in/out the image. If the image is not scaled, then ever thing is fine. But once I scaled the image and draw the line, the position is not coming correctly. Can you correct me, what's my mistake?
package imagetest;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class ZoomAndDraw extends JPanel
private java.awt.image.BufferedImage image = null;
private Line2D.Double line = null;
private double scale = 1.0;
private int value = 16;
private double translateX = 0.0;
private double translateY = 0.0;
private MouseManager manager = null;
public ZoomAndDraw()
line = new Line2D.Double();
readImage();
manager = new MouseManager(this);
addMouseListener(manager);
addMouseMotionListener(manager);
private void readImage()
try
image = javax.imageio.ImageIO.read(new java.io.File("D:/IMG.JPG"));
catch (Exception ex)
@Override
public Dimension getPreferredSize()
if (image != null)
int w = (int) (scale * image.getWidth());
int h = (int) (scale * image.getHeight());
return new Dimension(w, h);
return new Dimension(640, 480);
@Override
protected void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if (image == null)
return;
double x = (getWidth() - scale * image.getWidth()) / 2;
double y = (getHeight() - scale * image.getHeight()) / 2;
g2.translate(x, y); // move to center of image
g2.scale(scale, scale); // scale
translateX = 0 - x * (1 / scale);
translateY = 0 - y * (1 / scale);
g2.translate(translateX, translateY); // move back
g2.drawImage(image, 0, 0, this);
g2.setColor(Color.RED);
g2.draw(line);
g.dispose();
public void setLine(Point start, Point end)
line.setLine(start, end);
repaint();
public void addLine(Point start, Point end)
line.setLine(start, end);
repaint();
public void ZoomIn()
value++;
scale = (value + 4) / 20.0;
revalidate();
repaint();
public void ZoomOut()
if (value <= -3)
return;
value--;
scale = (value + 4) / 20.0;
revalidate();
repaint();
class MouseManager extends MouseAdapter
ZoomAndDraw component;
Point start;
boolean dragging = false;
public MouseManager(ZoomAndDraw displayPanel)
component = displayPanel;
@Override
public void mousePressed(MouseEvent e)
start = e.getPoint();
dragging = true;
@Override
public void mouseReleased(MouseEvent e)
if (dragging)
component.addLine(start, e.getPoint());
component.repaint();
dragging = false;
@Override
public void mouseDragged(MouseEvent e)
Point end = e.getPoint();
if (dragging)
component.setLine(start, end);
component.repaint();
else
start = end;
public static void main(String[] args)
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ZoomAndDraw zoomAndDraw = new ZoomAndDraw();
//Zoom in call
zoomAndDraw.ZoomIn();
zoomAndDraw.ZoomIn();
zoomAndDraw.ZoomIn();
frame.add(zoomAndDraw);
frame.setPreferredSize(new Dimension(640, 480));
frame.setSize(new Dimension(640, 480));
frame.setVisible(true);
}Thanks and Regards
Raja.Hi,
I'm having one more doubt. Just assume, after calling the ZoomIn(), I am drawing a line.
Subsequent ZoomIn() calls (let's say 5 times), changed the actual line position. How do I synchronize the zoom in call with the line coordinates?
public void FireZoomIn()
new Thread(new Runnable()
public void run()
try
Thread.sleep(3000);
catch (InterruptedException iex)
int count = 0;
while (count++ < 5)
ZoomIn();
}).start();
public void mouseReleased(MouseEvent e)
if (dragging)
component.addLine(start, e.getPoint());
component.repaint();
component.FireZoomIn();
dragging = false;
}Thanks and Regards
Raja. -
How to draw horizontal line at the end of table for multiple line items
Dear Experts,
Pls can anyone help me how to draw horizontal line at the end of table for multiple line items . kindly help me regarding this
Thanks
Ramesh ManoharanHi
I tried as per your logic but it is not solving my problem . when i am gone to table painter it is showing line type 1 and line type 2
is below format.. if u see here line type 1 bottom line and line type 2 top line both are same.. so how to avoid this ?
line type 1
line type 2 -
How to draw a line using JSP?
Does anyone know how to draw a line using a JSP? Any help is much appreciated.
Regards,
Navin Pathuru.Graphics classes are useless in JSP files; you can only output HTML tags to the client browser.
You should be able to give just about any presentation look that you need with HTML and CSS. Have you played with styles? Here's a simple example that works in IE 5+ and Netscape 4.7:
<HTML>
<HEAD>
<STYLE>
.box {
border-style:solid;
border-color:black;
border-right-width: 1px;
border-top-width: 1px;
border-left-width: 1px;
border-bottom-width: 1px;
.line {
border-right-width: 1px;
border-top-width: 0px;
border-left-width: 0px;
border-bottom-width: 0px;
border-style: solid;
border-color: red;
width:1pt;
height:100%;
</STYLE>
</HEAD>
<BODY>
<TABLE CELLPADDING=1 CELLSPACING=0 WIDTH=100>
<TR><TD ALIGN=CENTER><SPAN CLASS="box">Field One</SPAN></TD></TR>
<TR HEIGHT=50><TD ALIGN=CENTER><SPAN CLASS="line">�</SPAN></TD></TR>
<TR><TD ALIGN=CENTER><SPAN CLASS="box">Field Two</SPAN></TD></TR>
<TR HEIGHT=50><TD ALIGN=CENTER WIDTH=50%><SPAN CLASS="line">�</SPAN></TD></TR>
<TR><TD ALIGN=CENTER><SPAN CLASS="box">Field Three</SPAN></TD></TR>
</TABLE>
</BODY>
</HTML>
Have fun! -
How to draw a line???
I am a long time Photoshop user, but new to "Elements". I cannot figure out how to draw a line??? The Help says "To draw a line or arrow...... 1. In the Editor, select the Line tool." Ummm.....WHERE??? HOW??? If I knew how to select the Line tool I wouldn't have gone to the Help file.
Where is the "Editor"?? All I see at the top in the "Rectangular Marquee Tool" and the "Elliptical Marquee Tool" .....I see no Line tool on the left (where it used to be in PhotoShop) or on the top.
JeffJeff,
I use PEv.3. The line tool is accessed via the shape selection tool.
Click U. Hold the shift key as you drag and you will have a straight line.
Editor refers to the component of Elements utilized for enhancement and manipulation. Organizer in the Win version deals with storage and structured organization, as well as special projects.
Ken -
Hi all,
I am working on a chart in Design studio on BI platform. The following screen
shot will depict the current state of my chart-
Now
I need to draw lines of different lengths and colors with certain distance from
X-axis, as shown below. (I drew those lines on a screen shot of my chart with
the help of MS paint
but
I need to do this with the help of design studio) . Basically I need help to
get the following output in design studio. So, question is HOW TO DRAW A LINE
IN DESIGN STUDIO?
Kindly,
help with this.
Please suggest me to get the output.
Thanks and Regards.
Rakesh.Hi Tammy,
Thanks for ur reply.
I'm using DS 1.3. and no need of dynamic changes of line on chart.
I just now gone through with CSS, but i didnt get the solution. i think somewhere im getting stuck with CSS.
Can u please suggest me the step by step procedure to draw a line using CSS.
Kindly help on this.
Thanks and Regards,
Rakesh -
How to draw a line of sin x and its area under the line?
Hi,
I know how to draw a line from two points. However, I do not know how to draw a line of function sin(x) and its area under the line. Anyone know where to read or how can I draw it, please help me. Thanks !!
Calvinuse Graphics2D:: draw(Shape)
create a class that implements Shape, and specifically the getPathIterator methods, in these methods you should return a path iterator that follows the sin/cos curve.
All fairly simple to do.
rob, -
How to draw a line(shortest distance) between two ellipse using SWING
how to draw a line(should be shortest distance) between two ellipse using SWING
any help will be appreciated
regardsimport java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class ELine extends JPanel {
Ellipse2D.Double red = new Ellipse2D.Double(150,110,75,165);
Ellipse2D.Double blue = new Ellipse2D.Double(150,50,100,50);
Line2D.Double line = new Line2D.Double();
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.green.darker());
g2.draw(line);
g2.setPaint(Color.blue);
g2.draw(blue);
g2.setPaint(Color.red);
g2.draw(red);
private void connect() {
double flatness = 0.01;
PathIterator pit = blue.getPathIterator(null, flatness);
double[] coords = new double[2];
double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
double min = Double.MAX_VALUE;
while(!pit.isDone()) {
int type = pit.currentSegment(coords);
switch(type) {
case PathIterator.SEG_MOVETO:
case PathIterator.SEG_LINETO:
Point2D.Double p = getClosestPoint(coords[0], coords[1]);
double dist = p.distance(coords[0], coords[1]);
if(dist < min) {
min = dist;
x1 = coords[0];
y1 = coords[1];
x2 = p.x;
y2 = p.y;
break;
case PathIterator.SEG_CLOSE:
break;
default:
System.out.println("blue type: " + type);
pit.next();
line.setLine(x1, y1, x2, y2);
private Point2D.Double getClosestPoint(double x, double y) {
double flatness = 0.01;
PathIterator pit = red.getPathIterator(null, flatness);
double[] coords = new double[2];
Point2D.Double p = new Point2D.Double();
double min = Double.MAX_VALUE;
while(!pit.isDone()) {
int type = pit.currentSegment(coords);
switch(type) {
case PathIterator.SEG_MOVETO:
case PathIterator.SEG_LINETO:
double dist = Point2D.distance(x, y, coords[0], coords[1]);
if(dist < min) {
min = dist;
p.setLocation(coords[0], coords[1]);
break;
case PathIterator.SEG_CLOSE:
break;
default:
System.out.println("red type: " + type);
pit.next();
return p;
public static void main(String[] args) {
final ELine test = new ELine();
test.addMouseListener(test.mia);
test.addMouseMotionListener(test.mia);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(test);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
EventQueue.invokeLater(new Runnable() {
public void run() {
Graphics g = test.getGraphics();
g.drawString("drag me", 175, 80);
g.dispose();
private MouseInputAdapter mia = new MouseInputAdapter() {
Point2D.Double offset = new Point2D.Double();
boolean dragging = false;
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
if(blue.contains(p)) {
offset.x = p.x - blue.x;
offset.y = p.y - blue.y;
dragging = true;
public void mouseReleased(MouseEvent e) {
dragging = false;
public void mouseDragged(MouseEvent e) {
if(dragging) {
double x = e.getX() - offset.x;
double y = e.getY() - offset.y;
blue.setFrame(x, y, blue.width, blue.height);
connect();
repaint();
} -
How to execute a method after page Load?
My question is very similar to what was discussed in following thread:
How to execute a method after page Load?
My requirement is that I want to run a method in backing bean of a page, immediately after the page gets loaded. In that method I want to invoke one of the method action included in the pagedef of this page, conditionally.
I tried using the approach given in the above thread, i.e to use <f:view afterPhase="#{backing_security.setPermPriv}">, but the problem is that our page is not using 'f:view' , so I explicitly added one f:view with afterPhase property set , but it is not working, page it self is not getting loaded, it is throwing the error:
Root cause of ServletException.
java.lang.IllegalStateException: <f:view> was not present on this page; tag [email protected]e8encountered without an <f:view> being processed.
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.setProperties(UIXComponentELTag.java:108)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:733)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1354)
at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.doStartTag(UIXComponentELTag.java:71)
at oracle.adfinternal.view.faces.taglib.UIXQueryTag.doStartTag(UIXQueryTag.java:41)
at oracle.adfinternal.view.faces.unified.taglib.UnifiedQueryTag.doStartTag(UnifiedQueryTag.java:51)
at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:262)
at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
at oracle.jsp.runtimev2.ShortCutServlet._jspService(ShortCutServlet.java:89)
at oracle.jsp.runtime.OracleJspBase.service(OracleJspBase.java:29)
at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:665)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:387)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:822)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:746)
Please help to resolve this issue, or am I doing anything wrong?Hi,
I assume that your view is a page fragment and here - indeed - the f:view tag cannot be used. If you use ADF then one option would be to use a custom RegionController on the binding layer to listen for the render phase to invoke the method. Another option would be to use a hidden field (output text set to display="false" and have this component value referencing a managed bean property. The managed bean property's getter method can now be used to invoke the method you want to run upon view rendering
Frank -
How to do data validation after each load
Hi all,
How to do data validation after each load.
please send to : [email protected]
bhaskarHi Bhaskar,
Check these posts:
Re: Validation of data in BW?
Re: validate data
Bye
Dinesh -
How to draw multiple lines on same panel??
hiya
i would like to know how can I draw multiple lines on the same panel ?? I have already use repaint(); but it just come out the lastest line (say line 3) i draw .......those previous lines(say line 1 and 2) are disappear ........
Thanks for your help matehttp://www.java2s.com/ExampleCode/2D-Graphics/Line.htm
-
How to draw a line in smartforms!
Hello ABAPers,
In smartform, I am having a table. Every 3 rows I want to draw a line. How can I do that in Smartforms?
Thanks,hi Naren,
Check these links out
drawing line in smartforms
Re: Smartforms - Line Height
Re: smartforms blank line
Regards,
Santosh -
How to draw vertical lines in SMART FORMS
Hi Guys,
Can anyone please let me know how to draw vertical and horizontal lines in smart forms, i have to do this in the secondary window.
thanks,
RameshHi Ramesh,
In the window output options you have option of check box to get lines.
Then you need to give the spacing for vertical and horizontal.
Another option is putting a template on window and getting the boxes, but it is quite little bit complex.
Put the cursor on the WINDOW in which the lines you want.
Right click on it>create>complex section.
In that select the TEMPLATE radio button.
Goto TAB TEMPLATE.
Name: give some name of line.
From: From coloumn.
To: To coloumn
Height: specify the height of the line.
Next give the coloumn widths.
Like this you can draw the vertical and horzontal lines.
If the above option doesnot workout then u can try the below option also
any how you can draw vertical and horizontal lines using Template and Table.
for Template First define the Line and divide that into coloumns and goto select patterns and select the required pattern to get the vertical and horizontal lines.
For table, you have to divide the total width of the table into required no.of columns and assign the select pattern to get the vertical and horizontal lines.
if this helps, reward with points.
Regards,
Naveen -
How to draw a line on ADF page between two nodes for mapping.
Hi everyone,
Does anyone have a solution that how can I wiring two points by drawing a line on ADF pages.
My scenario is user want to do a mapping between two xml files. We will build an ADF faces page. This page have two parts, left part contains one tree(base on the source xml), right part is the destination tree(target xml). User can drag an node from left and drop to right. Meantime, a line will be created to connect two node, it would be perfect that when user scroll down the page, or extend the tree node, the line between source and target will be remain connection two node.
Does anyone have a solution for this, thanks in advance.
Hongfu.so you want to do something like. xsl mapper in soa
http://www.haertfelder.com/images/pSoaBPEL3.png
i can think of using javascript.. not sure... neeed extra programming..
Maybe you are looking for
-
Mobile Broadband does not work on HP mini 110
This is the my device: $ lsusb | grep Gobi Bus 001 Device 077: ID 03f0:1f1d Hewlett-Packard un2400 Gobi Wireless Modem sometimes another result: $ lsusb | grep Gobi Bus 001 Device 020: ID 03f0:201d Hewlett-Packard un2400 Gobi Wireless Modem (QDL mode
-
Large Text Being Chopped / Truncated
Hi, I have a marque displaying some text, but the Text is being chopped at the Top. I have tried increasing the height but no difference. This also happens on some of my Page Titles,and I don't know how to correct it. The Code is as follows (In the P
-
ITunes Error when trying to download movie
Hi, I get the same error over and over again when trying to download a purchased movie in iTunes (10.1.2) I was able to download the "Extras" and other content downloads from the iTunes Store, but the movie does not. I keep getting the message that a
-
Insert Symbols in Adobe Reader 11
Hi, I'd like to know how to insert delta symbols into an interactive Adobe Reader form (I have version 11,0,3,37 with windows 7)... Copying and pasting does not work... Thanks! Clara
-
How to keep my playlists and ratings in iTunes after reinstalling Windows ?
Hi, I would like to know how can I keep my playlists and ratings after reinstalling a fresh copy of windows. Thank you in advance,