If statement in paint
Can anyone help.using eventlistener ,with CheckboxeGroup,I,m trying to put a if statement in paint so when I select the
Checkbox it paints, seems simple, but been at it for days cannot suss it.
Any help appreciated
THANK YOU
Since you have some code allready this was my version:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Painting extends Panel implements ActionListener{
public static final int ON = 0;
public static final int OFF = 1;
private int flag = ON;
public Painting(){
JCheckBox checkBox = new JCheckBox();
checkBox.addActionListener(this);
JFrame frame = new JFrame();
frame.getContentPane().add(checkBox,BorderLayout.NORTH);
frame.getContentPane().add(this,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100,150);
frame.setVisible(true);
public void actionPerformed(ActionEvent e){
if(flag==ON){
flag= OFF;
}else{
flag=ON;
repaint();
public void paint(Graphics g){
switch(flag){
case OFF:
g.fillRect(20,20,50,50);
break;
case ON:
g.fillOval(20,20,50,50);
break;
public static void main(String[] args){
new Painting();
}
Similar Messages
-
How to wait until all components painted?
Hi - I have searched for hours for an answer to this and have yet to find something so any help is much appreciated!
Ive posted some code below to simulate the problem im facing. This is a simple frame which has a couple of custom jPanels embedded within it.
When this is run, the first 3 lines i see are: I want this comment to be the last thing output
Now finished panel paint
Now finished panel paintBut, as this output suggests, i want the "I want this comment to be the last thing output" line to be displayed after the two panels are completely painted on the screen (in real life i need to know my components are displayed before the program can move on to further processing). Of course, if you cause a repaint you see the "now finished panel paint" each time, but im not interested in this, im simply interested in how to overcome this when the frame is first created and shown.
Ive tried everything i can think of at the "// ***** What do i need to put here? ******" position but nothing seems to work... In short my question is how can i construct my frame and get it to ensure that all components are fully displayed before moving on?
Sorry if the answer to this is obvious to someone who knows these things, but its driving me mad.
Cheers
import javax.swing.*;
import java.awt.*;
public class Frame1 extends JFrame {
public static void main(String[] args) {
Frame1 frame1 = new Frame1();
// ***** What do i need to put here? ******
// to ensure that the System.err.. call below
// is only executed once both panels paint methods
// have finished?????
System.err.println("I want this comment to be the last thing output");
System.err.flush();
public Frame1() {
this.getContentPane().setLayout(new FlowLayout());
MyPanel p1 = new MyPanel(); p1.setBackground(Color.red);
MyPanel p2 = new MyPanel(); p2.setBackground(Color.green);
this.getContentPane().add(p1, null);
this.getContentPane().add(p2, null);
this.pack();
this.setVisible(true);
class MyPanel extends JPanel {
Dimension preferredSize = new Dimension(200,200);
public Dimension getPreferredSize() { return preferredSize; }
public MyPanel () { }
public synchronized void paintComponent(Graphics g) {
super.paintComponent(g); //paint background
// do some irrelevant drawing to simulate a bit of work...
for (int i=0; i<200; i+=20) {
g.drawString("help please!",50,i);
System.err.println("Now finished panel paint"); System.err.flush();
} // end of MyPanel
}Thanks both for your replies.
When doing the "Runnable runnable = new Runnable(){public void run(){ frame1.paint(frame1.getGraphics());....." method i sometimes see
Now finished panel paint
Now finished panel paint
I want this comment to be the last thing output
Now finished panel paint
Now finished panel paintwhich is a pain.
As for making a new Runnable to do the system.err.println and then doing the SwingUtilities(invoke) on that runnable, that didnt work for me at all.
So... in the end, my solution was to have the paint method set a boolean when finished and the main program sleep while this is false
// Dont want to sleep for say a few seconds as cant be sure
//painting will be finished, must monitor state of painting ...
//therefore use while loop
while (!isOk) { // isOk is true when both panel paint methods complete
System.err.println("Waiting......");
try{ Thread.sleep(300 /* wait some time */); }
catch(Exception e){}
System.err.println("Thankfully this works");which is a kind of mixture of both your suggestions i guess!
Thanks for your help, much appreciated. -
Graphic keeps disappearing and getting painted over
I am not quite sure what is going on here, but I think that my background is being repainted after I paint my rectangles on the screen, any help on what is going on here would be greatly appreciated.
The way the code is currently set up is when I come into the method, I set my state to -1,
The rectangle will then init itself and then go check my control variables,
The control variables turn the rectangle the appropriate color
since I have rip_staus_code = 10 it turns green, although
The problem is after it turns green;
the rectangle disappears!!!
and I cant quite see where in the code I am repainting over the top of it.....
Thank You
jsg
protected int rx1State = -1
public void paintChildren(Graphics g){
super.paintChildren(g);
Graphics2D g2d = (Graphics2D)g;
if(rx1State == -1){
rx1 = new Rectangle2D.Double(29,110,63,57);
g.setColor(testColor);
g2d.fill(rx1);
g.setColor(Color.black);
g2d.setStroke(graphicStroke);
g.setFont(graphicLabelFont);
g2d.draw(rx1);
g.drawString("rect one",49,142);
//turn rectangle one green
if(rx1State != 0 && ss.rtRip1_status_code >= 9){ //rip_staus_code is set to 10, so turns green
drawChangedRect(g,rx1,Color.green);
g.drawString("rect one",49,142);
rx1State = 0;
//turns rectangle one red
if(rx1State != 2 && ss.rtRip1_status_code < 9){
drawChangedRect(g,rx1,Color.red);
g.drawString("Rx1",49,142);
System.out.println("Turned Rx1 red");
rx1State = 2;
//turns Rectangle one white
if(rx1State != 3 && (!ss.ColorRX1RIP1 | !ColorARROWABred )){ //ColorRX1RIP1=true, colorArrowABred=T
drawChangedRect(g,rx1,upstreamColor);
g.drawString("Rx1",49,142);
rx1State = 3;I see a couple things wrong here.
First, why are you overwriting paintChildren? If you want to do custom drawing, do that in paintComponent.
Second, never change state inside a painting method. Why? Because you can't control how often repaint is called. Covering or partically covering the window, resizing the window, or programmatic calls to repaint will all cause the method to be called, and sometimes only on a portion of your component (such is the case when only partially covered). This can cause very weird visual effects. In your program, the first call to paint will paint the appropriate rectangle but then set the state flag. There is probably another call to repaint somewhere which will then repaint the component without the rectangle (because the state has now changed), painting over your rectangles. The solution, don't change the state in paint. -
On implementingthe paint method, the panel does not up
Hi,
I have a panel over which i am adding a second panel.
the second panel appears but when i implement the paintmethod() of second panel, it does not show...
what can be the reason???
deepakhi!
i included the statement super.paint(g); in the paint method and now i can see the panel.
Following is the paint() method i have written, the on;y problem left is that i can't see the images i had drawn...otherwise line and rectangles are coming fine
super.paint(g);
if(showImage)
Point pe0 = new Point(180, 110);
Point pe1 = new Point(180, 280);
Point p0 = new Point(138, 182);
Point ce0 = new Point(120, 75);
Point ce2 = new Point(240, 75);
Point ce1 = new Point(120, 380);
Point ce3 = new Point(240, 380);
g.drawImage(verticalCloudImage, (int)p0.getX() - 20, (int)p0.getY() - 85, this);
g.drawImage(peImage, (int)pe0.getX(), (int)pe0.getY(), this);
g.drawImage(peImage, (int)pe1.getX(), (int)pe1.getY()+35, this);
g.drawImage(cloudImage, (int)ce0.getX()-88, (int)ce0.getY()-52, this);
g.drawImage(ceImage, (int)ce0.getX(), (int)ce0.getY(), this);
g.drawImage(cloudImage, (int)ce2.getX(), (int)ce2.getY()-45, this);
g.drawImage(ceImage, (int)ce2.getX(), (int)ce2.getY(), this);
g.drawImage(cloudImage, (int)ce1.getX()-88, (int)ce1.getY()-22, this);
g.drawImage(ceImage, (int)ce1.getX(), (int)ce1.getY(), this);
g.drawImage(cloudImage, (int)ce3.getX(), (int)ce3.getY()-22, this);
g.drawImage(ceImage, (int)ce3.getX(), (int)ce3.getY(), this);
int ceHeight = ceImage.getHeight(this);
int ceWidth = ceImage.getWidth(this);
int peHeight = peImage.getHeight(this);
int peWidth = peImage.getWidth(this);
int pHeight = pImage.getHeight(this);
int pWidth = pImage.getWidth(this);
g.drawLine((int)ce0.getX() + ceWidth/2, (int)ce0.getY() + ceHeight,
(int)pe0.getX() + peWidth/2, (int)pe0.getY());
g.drawLine((int)ce2.getX() + ceWidth/2, (int)ce2.getY() + ceHeight,
(int)pe0.getX() + peWidth/2, (int)pe0.getY());
g.draw3DRect((int)pe0.getX() + peWidth/2 - 3, (int)pe0.getY() + peHeight - 1,
5, (int)p0.getY() - (int)pe0.getY() - peHeight - 2+23, true);
g.draw3DRect((int)p0.getX() + pWidth/2 - 10, (int)p0.getY() + peHeight - 1+20,
5, (int)pe1.getY() - (int)p0.getY() - peHeight + 2+15, true);
g.fill3DRect((int)pe0.getX() + peWidth/2 - 3, (int)pe0.getY() + peHeight - 1,
5, (int)p0.getY() - (int)pe0.getY() - peHeight - 2+23, true);
g.fill3DRect((int)p0.getX() + pWidth/2 - 10, (int)p0.getY() + peHeight - 1+20,
5, (int)pe1.getY() - (int)p0.getY() - peHeight + 2+15, true);
g.drawLine((int)ce1.getX() + ceWidth/2, (int)ce1.getY(),
(int)pe1.getX() + peWidth/2, (int)pe1.getY() + peHeight+35);
g.drawLine((int)ce3.getX() + ceWidth/2, (int)ce3.getY(),
(int)pe1.getX() + peWidth/2, (int)pe1.getY() + peHeight+35); -
Synth/Nimbus: how to implement a new UI-delegate?
my first steps in the region - so please be lenient :-)
Problem is that nearly everthing in the Synth package is package private, looks like a completely sealed shop. Even the ui-delegate creation doesn't follow the usual pattern (register the class and let the manager instantiate it later) but is hard-coded - hard to belief, but truely constructors called - in the SynthLookAndFeel. There is no way to extend that I can see.
Actually, the instantiation doesn't hurt us (== SwingX), because our AddOn mechanism takes care of it (and does a good job, fortunately).
what does hurt, afaics, is the fact that the delegates can't be implemented the synth-way: using context, state, region, painter ... many of those are invisible to external classes. It starts with the simple update method, standard in all synth delegates is
public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c);
SynthLookAndFeel.update(context, g); // invisble
context.getPainter(). // invisible
paintListBackground(context,
g, 0, 0, c.getWidth(), c.getHeight());
context.dispose(); // invisible
paint(g, c);
} Pretty sure I'm overlooking something obvious ... it can't be that the LAF was designed to not be extensible with new component types, or can it?
Any pointers, hints, examples highly welcome!.
Thanks
Jeanette
BTW: this is a cross-post from the swinglabs forum to get as wide a spread as possible :-) The discussion there is at
[http://forums.java.net/jive/thread.jspa?threadID=65533]Ok.. so here's my understanding.
Suppose we create a bunch of new SwingX components.
public class XComponent extends JComponent {
public final static String uiClassId = "XComponentUI";
public XComponent() {
updateUI();
@Override
public void updateUI() {
setUI((XComponentUI) UIManager.getUI(this));
public void setUI(XComponentUI ui) {
super.setUI(ui);
}Now we need to make sure UIManager.getUI(this) actually works. So...
UIManager.put(XComponent.uiClassID,"blabla.SynthXComponentUI");Now we need to provide SynthXComponentUI.
package blabla;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.synth.*;
public class SynthXComponentUI extends ComponentUI{
SynthStyle style;
SynthStyle leftStyle;
SynthStyle rightStyle;
public static ComponentUI createUI(JComponent target) {
return new SynthXComponentUI();
@Override
public void installUI(JComponent c) {
super.installUI(c);
style = SynthLookAndFeel.getStyle(c, XRegion.XCOMPONENT);
leftStyle = SynthLookAndFeel.getStyle(c, XRegion.XCOMPONENT_LEFT);
rightStyle = SynthLookAndFeel.getStyle(c, XRegion.XCOMPONENT_RIGHT);
protected SynthContext getContext(JComponent c, Region r, SynthStyle style) {
int state = 0;
state |= c.isEnabled()?SynthConstants.ENABLED:SynthConstants.DISABLED;
state |= c.isFocusOwner()?SynthConstants.FOCUSED:0;
java.awt.Point mousePoint = c.getMousePosition();
if(mousePoint != null) {
if(r == XRegion.XCOMPONENT) {
state |= SynthConstants.MOUSE_OVER;
}else if(r == XRegion.XCOMPONENT_LEFT && mousePoint.x < c.getWidth()/2) {
state |= SynthConstants.MOUSE_OVER;
}else if(r == XRegion.XCOMPONENT_RIGHT && mousePoint.x > c.getWidth()/2) {
state |= SynthConstants.MOUSE_OVER;
return new SynthContext(c,r,style,state);
@Override
public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c, XRegion.XCOMPONENT, style);
((SynthXPainter) style.getPainter(context)).paintXComponentBackground(
context, g, 0, 0, c.getWidth(), c.getHeight());
context = getContext(c, XRegion.XCOMPONENT_LEFT, style);
((SynthXPainter) leftStyle.getPainter(context)).paintXComponentLeftBackground(
context, g, 0, 0, c.getWidth()/2,c.getHeight());
context = getContext(c,XRegion.XCOMPONENT_RIGHT,style);
((SynthXPainter) rightStyle.getPainter(context)).paintXComponentLeftBackground(
context, g,c.getWidth()/2, 0, c.getWidth()/2,c.getHeight());
}Here, I'm pretending the Component is broken into three regions. The whole component itself serves as one region. And then the left and right side of the component serves as subregions. I assume all regions are defined in this class called XRegion.
package blabla;
import javax.swing.plaf.synth.Region;
public class XRegion extends Region{
public static final XRegion XCOMPONENT = new XRegion("XComponent","XComponentUI", false);
public static final XRegion XCOMPONENT_LEFT = new XRegion("XComponentLeft",null,true);
public static final XRegion XCOMPONENT_RIGHT= new XRegion("XComponentRight",null,true);
//other regions would also be defined
public XRegion(String name, String ui, boolean subComponent) {
super(name,ui,subComponent);
}Presumebly, this XRegion class would contain all the new defined regions for your SwingX components.
In my UI, I'm also assuming that the StyleFactory returns a style whose SynthPainter is something called SynthXPainter.
package blabla;
import javax.swing.plaf.synth.SynthPainter;
import javax.swing.plaf.synth.SynthContext;
import java.awt.Graphics;
public class SynthXPainter extends SynthPainter{
public void paintXComponentBackground(SynthContext context, Graphics g,int x, int y, int w, int h) {}
public void paintXComponentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) {}
public void paintXComponentLeftBackground(SynthContext context, Graphics g,int x, int y, int w, int h) {}
public void paintXComponentRightBackground(SynthContext context, Graphics g,int x, int y, int w, int h) {}
//other painting methods for SwingX would be defined
}The SynthXPainter class would contain all the new paintXXX methods to paint your SwingX components. Much like SynthPainter does for Swing.
Then there's the SynthContext. In the UI I provided a method called getContext. All it pretty much does is calculate the state of the component and returns a new SynthContext based on that state. The only thing unique about it is that I decided to set the MOUSE_OVER flag only if the the mouse is over the region being painted. With the appropriate SynthContext and SynthXPainter, I can call the methods I need to paint XComponent.
Note that I don't need to call SynthContext#dispose (which is invisible) on the objects I create. This is because the SynthContext is not cached anywhere when using the public api for the class.
Now we need to provide a SynthStyleFactory that returns a SynthStyle appropriate for the regions.
SynthLookAndFeel.setStyleFactory(new SynthStyleFactory() {
SynthStyleFactory wrapper = SynthLookAndFeel.getStyleFactory();
@Override
public SynthStyle getStyle(JComponent c, Region id) {
if (id instanceof XRegion) {
if (id == XRegion.XCOMPONENT) {
return new XStyle(new XComponentPainter());
} else if (id == XRegion.XCOMPONENT_LEFT) {
return new XStyle(new XComponentLeftPainter());
} else if (id == XRegion.XCOMPONENT_RIGHT) {
return new XStyle(new XComponentRightPainter());
} else {
throw new IllegalArgumentException("Unkown region!");
} else {
wrapper.getStyle(c, id);
});Where I defined XStyle like so,
package blabla;
import java.awt.Color;
import java.awt.Font;
import javax.swing.plaf.synth.*;
public class XStyle extends SynthStyle{
private SynthXPainter painter;
public XStyle(SynthXPainter painter) {
this.painter = painter;
@Override
public SynthPainter getPainter(SynthContext context) {
return painter;
@Override
protected Font getFontForState(SynthContext context) {
throw new UnsupportedOperationException("Not supported yet.");
@Override
protected Color getColorForState(SynthContext context, ColorType type) {
throw new UnsupportedOperationException("Not supported yet.");
}I didn't actually implement XComponentPainter, XComponentLeftPainter, and XComponentRightPainter. But they would extend SynthXPainter and override the appropriate painting methods. -
Impressionist brush only changes white and very light colours
I'm new to Photoshop Elements and am trying to grapple with the Impressionist brush. It seems to function like CS5's Art History brush except that I cannot get it to affect mid and dark value areas. It appears no matter what the area or tolerance settings to change only whites and very light colours. Is this a known issue or am I missing something?
Thanks.Try resetting the impressionist brush tool by clicking on the
little downturned arrow and choose reset tool.
It's somewhat similar to photoshop except, you can't choose
a history state to paint from, so make sure your not painting
on a blank layer. To effect the photo, you have to paint on the actual layer
that photo is on.
MTSTUNER -
Table / Function that defines if a program is being executed(not-so-urgent)
Hi,
Could you please help me.
I required to know if a program is being executed in a specific moment.
If you know any table or a function, than indicates if a program is being executed in that moment please tell me.
I search for a function and found this one, but i dont know how to use it.
CALL FUNCTION 'ENQUEUE_ESFUNCTION'
EXPORTING
MODE_TFDIR = 'E'
FUNCNAME =
X_FUNCNAME = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
Please help me !!!!!.
Thanks for your help and best regards.
JRZ.
<Subject line changed>
Edited by: Suhas Saha on Oct 28, 2011 10:37 AMHi,
You can use transaction code STAT
writer/painter reports -view stats via SE16 in table T803J
reports and transactions execution info is stored in table MONI.
Also check this sample code from other thread.
internal tables for use counterdata:
begin of list occurs 5.
include structure sapwlserv.
data: end of list.
data: begin of applicat occurs 0.
include structure sapwlustcx.
data: end of applicat.
data: begin of applica_ occurs 0.
include structure sapwlustcx.
data: end of applica_.
data: begin of applicau occurs 0,
entry_id like sapwlustcx-entry_id,
account like sapwlustcx-account,
count like sapwlustcx-count,
: end of applicau.
data: wa_applicau like applicau.
*& Form MONI
form moni.
data: l_host like sapwlserv-hostshort.
m_start = p_usedt.
get server
call function 'SAPWL_SERVLIST_GET_LIST'
tables
list = list.
do.
loop at list.
loop on server
check not list-instshort is initial.
l_host = list-instshort.
get statistics per month and server
perform workload using m_start l_host.
endloop.
add 31 to m_start.
if m_start > sy-datum.
exit.
endif.
enddo.
sort applica_ by entry_id.
sort applicau by entry_id count descending.
endform. " MONI
*& Form WORKLOAD
form workload using p_start like sy-datum
p_host like sapwlserv-hostshort.
refresh: applica_.
read application statistic from MONI
call function 'SAPWL_WORKLOAD_GET_STATISTIC'
exporting
periodtype = 'M'
hostid = p_host
startdate = p_start
only_application_statistic = 'X'
tables
application_statistic = applica_
exceptions
unknown_periodtype = 1
no_data_found = 2
others = 3.
sort applica_ by entry_id account.
loop at applica_ where entry_id(1) ge 'Y'. "#EC PORTABLE
clear wa_applicau-entry_id.
wa_applicau-entry_id(25) = applica_-entry_id.
wa_applicau-account = applica_-account.
wa_applicau-count = applica_-count.
collect wa_applicau into applicau.
endloop.
sort applicau by entry_id count descending.
applica_-ttype = space.
applica_-account = space.
modify applica_ transporting ttype account where ttype ne space.
collect only enhancements statistic
if p_temp = 'X'.
loop at applica_.
applica_-entry_id+25(48) = space.
collect applica_ into applicat.
endloop.
else.
loop at applica_ where entry_id(1) ge 'Y'. "#EC PORTABLE
applica_-entry_id+25(48) = space.
collect applica_ into applicat.
endloop.
endif.
endform. " WORKLOAD
Thanks & regards. -
FRUSTRATED! Need help, please!
I have written a program for my Pacman maze (see code below).
The program compiles and displays the maze, but the problem is when I minimize the window and miximize it again, the display disappears or becomes corrupted. I thought I need to use repaint or update. HOWEVER this is where it gets interesting. When I have any kind of loop in my paint() method, for example the nested "for" loop in the code below which paints the maze on the screen based on the "board" array, each time I resize or minimize the window, the display becomes corrupted. BUT, if I take the loops out and just use any draw statement to paint something on the screen, I dont have the same problem. And the program repaints the screen perfectly when the window is resized or minimized.
Please help me, I have already spent a long time on this problem.
THanks in advance.
here is the code.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Maze extends JFrame
static int board[][] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1},
{1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1},
{1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1},
{1,1,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,1,1},
{0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
{1,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1},
{1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1},
{1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1},
{1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1},
{1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} };
int count1 = 0;
int count2 = 0;
int xbound = 25;
int ybound = 50;
public Maze()
super ("PacMan Maze");
setSize(800,800);
show();
public void paint (Graphics g)
for(count1=0; count1 < 19; count1++)
for(count2=0; count2 < 19; count2++)
switch (board[count1][count2])
case 0:
g.setColor(Color.blue);
g.fillRect(xbound,ybound,35,35);
break;
case 1:
g.setColor(Color.white);
g.fillRect(xbound,ybound,35,35);
g.setColor(Color.blue);
g.drawRect(xbound,ybound,35,35);
break;
xbound = xbound + 35;
ybound = ybound + 35;
xbound = 25;
public static void main (String args[])
Maze app = new Maze();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e)
System.exit(0);
}I think you did not reset the xbound/ybound variables after the paint, therefore the numbers keep increasing each time the paint method is called.
Try setting both variables to 0 at the start of the paint method. -
I am doing a program with rectangles displayed random on a panel..How to format a statement in paint n actionListnerwhen a button is click?For eg: i have 10 rectangle in an array 0 to 9.. for every button tat is clicked.. a rectangle change it color? The problem with my codes is that i wont be able to click and see the color change..
Your question is quite vauge, and I can not identify the problem you are having. Are you cathcing the event raised by the button ActionEvent? Are you changing the colours of the rectangle once the button is clicked? are you painting the screen again to make sure the colour is change (in case JFrame is used you must use myFrame.validate()).
describe better :) -
Hi,
The buttons in NetBeans' toolbar, for example, don't have their content area filled. However, when rolling the mouse over them, the border is painted.
What are the properties needed to be enabled/disabled in order to acheive this effect? I've tried a bunch of them but without success.
Thank you.That didn't do it. Is there any chance the Look&Feel is messing with it? I'm using the Windows L&F on Windows XP.Works fine for me using JDK1.4.2 on XP.
the last clicked button keeps the "rollover" state, thus painting the border. I hope you know what I mean.No I don't know what you mean. Same comment as above.
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html
Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting -
If Statement in java.awt paint
import java.applet.Applet; //bring in the applet class
import java.awt.*; //bring in the graphics class
import java.awt.event.*; //bring in the event class
import java.text.DecimalFormat; //bring in the decimal format class
import java.lang.Float; //bring in the float class
public class Bmi extends Applet implements ActionListener { //begin program and start ActionListener
Label weight, height; //define Label variable
TextField weighttext, heighttext; //define TextField variables
Button calculate; //define button variables
float index, wt, ht, max, min; //define float variables
DecimalFormat fmt2 = new DecimalFormat("#.00"); //set decimal format for reals
public void init() { //begin init()
weight = new Label("Please enter your weight in Kg. (2 decimal places): "); //define content of Label weight
weighttext = new TextField(6); //define size of TextField
height = new Label("Please enter your height in Metres (2 decimal places): "); //define content of Label height
heighttext = new TextField(5); //define size of TextField
calculate = new Button("Calculate!!"); //define content of Button
add(weight); //add Label weight to the GUI
add(weighttext); //add TextField weighttext to the GUI
add(height); //add Label height to the GUI
add(heighttext); //add TextField heighttext to the GUI
add(calculate); //add button calculate to the GUI
calculate.addActionListener(this); //wait for button to be returned
wt = 0; //reset wt to 0
index = 0; //reset index to 0
ht = 0; //reset ht to 0
max = 0; //reset max to 0
min = 0; //reset min to 0
public void actionPerformed( ActionEvent e ) { //run upon return of button
wt = Float.parseFloat(weighttext.getText()); //convert weighttext from String to Float
ht = Float.parseFloat(heighttext.getText()); //covert heighttext from String to Float
repaint(); //refresh paint area
public float indexer() //begin indexer method
float ind; //delare local variable ind
ind = wt/(ht*ht); //perform calculation
return ind; //make indexer() the value of variable ind
} // end of indexer method
public float maxWeight() //begin maxWeight method
float maxwt; //declare local variable maxwt
final float UPPER = 25.0f; //declare variable UPPER as a float with a decimal value of 25.0
maxwt = UPPER*ht*ht; //perform calculation
return maxwt; //make maxWeight() the value of variable maxwt
} // end of maxWeight method
public float minWeight() //begin minWeight method
float minwt; //declare local variable minwt
final float LOWER= 20.0f; //declare variable LOWER as a float with a decimal value of 20.0
minwt = LOWER*ht*ht; //perform calculation
return minwt; //make minWeight() the value of variable minwt
} // end of minWeight method
public void paint(Graphics g) //begin paint method, define g as Graphics
index=indexer(); //covert method indexer() to variable index
max=maxWeight(); //convert method maxWeight() to variable max
min=minWeight(); //convert method minWeight() to variable min
g.setFont(new Font("Verdana", Font.ITALIC, 15)); //define font, weight and size
g.setColor(new Color(90,90,90)); //set new colour
g.drawRect(5,100,300,75); //define size of rectangle
g.setColor(new Color(255,107,9)); //set new colour
g.drawString("BMI is " + fmt2.format(index) + " for " + fmt2.format(wt) + "kg",20,120); //create string in paint, define its on screen position
g.drawString("Maximum bodyweight is " + fmt2.format(max) + "kg", 20,140); //create string in paint, define its on screen position
g.drawString("Minimum bodyweight is " + fmt2.format(min) + "kg", 20,160); //create string in paint, define its on screen position
} // end of paint method
} // end of Bmi classI have written the above code to calculate someones BMI (Body Mass Index). Basically as you can see it recieves a weight and height from the user and calculates the rest. But whilst that good I would like to know how I can make it tell the user something to the effect of "Your overweight" or "Your underweight". The if statement runs like this:
if (wt > max)This forum doesn't quite handle <> properly. The greater and less than symbols. So above you will see > this is the html character code for a greater than symbol so please read it as such.
And then if wt is greater than max then it will say "Your overweight".
But I can't figure out how to include it in the above program. Becuase it won't run in paint, atleast it won't the way I have done it previously. So can you think of any other ways?
Help much appreciated,
SimonThanks very much that works well.
Simon
My code now looks like this: import java.applet.Applet; //bring in the applet class
import java.awt.*; //bring in the graphics class
import java.awt.event.*; //bring in the event class
import java.text.DecimalFormat; //bring in the decimal format class
import java.lang.Float; //bring in the float class
public class Bmi extends Applet implements ActionListener { //begin program and start ActionListener
Label weight, height; //define Label variable
TextField weighttext, heighttext; //define TextField variables
Button calculate; //define button variables
float index, wt, ht, max, min; //define float variables
DecimalFormat fmt2 = new DecimalFormat("#.00"); //set decimal format for reals
public void init() { //begin init()
weight = new Label("Please enter your weight in Kg. (2 decimal places): "); //define content of Label weight
weighttext = new TextField(6); //define size of TextField
height = new Label("Please enter your height in Metres (2 decimal places): "); //define content of Label height
heighttext = new TextField(5); //define size of TextField
calculate = new Button("Calculate!!"); //define content of Button
add(weight); //add Label weight to the GUI
add(weighttext); //add TextField weighttext to the GUI
add(height); //add Label height to the GUI
add(heighttext); //add TextField heighttext to the GUI
add(calculate); //add button calculate to the GUI
calculate.addActionListener(this); //wait for button to be returned
wt = 0; //reset wt to 0
index = 0; //reset index to 0
ht = 0; //reset ht to 0
max = 0; //reset max to 0
min = 0; //reset min to 0
public void actionPerformed( ActionEvent e ) { //run upon return of button
wt = Float.parseFloat(weighttext.getText()); //convert weighttext from String to Float
ht = Float.parseFloat(heighttext.getText()); //covert heighttext from String to Float
repaint(); //refresh paint area
public float indexer() //begin indexer method
float ind; //delare local variable ind
ind = wt/(ht*ht); //perform calculation
return ind; //make indexer() the value of variable ind
} // end of indexer method
public float maxWeight() //begin maxWeight method
float maxwt; //declare local variable maxwt
final float UPPER = 25.0f; //declare variable UPPER as a float with a decimal value of 25.0
maxwt = UPPER*ht*ht; //perform calculation
return maxwt; //make maxWeight() the value of variable maxwt
} // end of maxWeight method
public float minWeight() //begin minWeight method
float minwt; //declare local variable minwt
final float LOWER= 20.0f; //declare variable LOWER as a float with a decimal value of 20.0
minwt = LOWER*ht*ht; //perform calculation
return minwt; //make minWeight() the value of variable minwt
} // end of minWeight method
public void you(Graphics g)
String statement;
if(wt > max) statement="You are very fat";
else if(wt < min) statement="You are very thin";
else statement="You are in the recommended weight range for your height";
g.drawString(statement, 20,210);
public void paint(Graphics g) //begin paint method, define g as Graphics
you(g);
index=indexer(); //covert method indexer() to variable index
max=maxWeight(); //convert method maxWeight() to variable max
min=minWeight(); //convert method minWeight() to variable min
g.setFont(new Font("Verdana", Font.ITALIC, 15)); //define font, weight and size
g.setColor(new Color(90,90,90)); //set new colour
g.drawRect(5,100,300,75); //define size of rectangle
g.setColor(new Color(255,107,9)); //set new colour
g.drawString("BMI is " + fmt2.format(index) + " for " + fmt2.format(wt) + "kg",20,120); //create string in paint, define its on screen position
g.drawString("Maximum bodyweight is " + fmt2.format(max) + "kg", 20,140); //create string in paint, define its on screen position
g.drawString("Minimum bodyweight is " + fmt2.format(min) + "kg", 20,160); //create string in paint, define its on screen position
} // end of paint method
} // end of BmiThanks again,
Simon -
Report painter: Financial statement debit credit indicator taken into account?
Hi,
When I create a report with report painter (FGI0) It does not take into account the debit / credit indicator of the FS statement.
Is this standard SAP or do I miss a setting?
kr,
KlundertHi Wolfgang,
Please refer to OSS note 663945. This will give you the transfer rule mapping for 0GLACCEXT.
Hope this helps.
Thanks,
Vivek -
Report Painter for B/S , P&L statements
Hii gurus
this is ramki...
Plssss help me in the making of Report painter for Balance Sheet and Profit And Loss Statements , as of now i didn't did Report Painter .
I have tried no.of times , i dont know the confg also...
My client is asking DR & Cr columns for the statements..
can any body plsssss forward to me report painter confg documentation...( atleat for base level confg )
helpers will b great appreciateble..
thanks in advance
regards
ramkiHi
i am sending you a sample of how to createa report in report painter follow it,
Main Steps in Creating a Report Using Report Painter
The illustration below shows the main steps in creating a report with Report Painter:
In this section, you learn how to create a Profit Center Accounting (PCA) report with Report Painter.
For these sample reports, you should focus on the tables that correspond to the SAP application areas with which you are working. The examples shown in this section have been created in Release 4.6C.
Sample Report for Gross Profit Margin
Bungee Corporation wants to use Report Painter to create a gross margin report. This Profit Center Accounting report uses data table GLPCT. The desired PCA report displays the gross margin for each profit center.
Below is an illustration of the completed gross margin report.
Prerequisites to Creating a Report with Report Painter
Before you can create a report with Report Painter, you need to:
Determine the table
Find the library
Create sets
Create variables
The following sections explain these prerequisites.
Determine the Table
Before you can start creating the report, you must decide on the table you need to use. In this example, we use table GLPCT in Profit Center Accounting.
Find the Library
Determine the library you want to use for the desired table.
If you need to create a library, on the SAP Easy Access screen, either:
From the navigation menu, choose SAP menu → Information systems → Ad hoc reports → Report painter → Report Writer → Library → Create.
In the Command field, enter transaction GR21 and choose .
In our example, we use existing library 8A2 for creating a report.
Create Sets
Create the required sets for your report. To create a set, on the SAP Easy Access screen, either:
From the navigation menu, choose SAP menu → Information systems → Ad hoc reports → Report painter → Report Writer → Set → Create.
In the Command field, enter transaction GS01 and choose .
Note that this procedure is not necessary for creating the report given in the example that follows.
Create Variables
Create any variables for the fields that must be entered before the report is executed. To create a variable, on the SAP Easy Access screen, either:
From the navigation menu, choose SAP menu → Information systems → Ad hoc reports → Report painter → Report Writer → Variable → Create.
In the Command field, enter transaction GS11 and choose .
Note that this procedure is not necessary for the sample report in the next section.
Creating a Report with Report Painter
When you are ready to create the report using Report Painter, use the following steps.
Example Task: Creating a report using Report Painter
1. On the SAP Easy Access screen, either:
o From the navigation menu, choose: SAP menu → Information systems → Ad hoc reports → Report painter → Report → Create.
o In the Command field, enter transaction GRR1 and choose .
2. On the Report Painter: Create Report screen:
a. In Library, enter the name of the library to be used for the report (for this example, 8A2).
b. In the Report, enter a name for your report and a short text description.
c. Choose Create.
1.
To help you better understand how to create a report in Report Painter, the next procedures explain the varying substeps. You can either:
o Define the rows (or rows with a formula)
o Define the columns (or columns with a formula)
o Define the general data selection
Define Rows
Example Task: Defining rows (including defining a row with a formula)
To start defining the rows, on the Report Painter: Create Report screen, double click on Row
On the Element definition: Row1 dialog box:
a. To include characteristics in the first row of the report, select the desired characteristics in the Available characteristics frame (for example, Account number)
b. Use to transfer the chosen characteristic to the Selected characteristics frame.
c. In From, enter the account number(s) you want to include in the row definition. Either enter to and from values or a group set (for example, the value 800000).
d. To enter the row heading, choose
On the Text maintenance dialog box:
a. In Short, enter the desired short text (for example, Revenue).
b. To copy the short text into the Medium and Long text fields, choose Copy short text.
c. To continue, choose
On the Element definition: Row1 dialog box:
a. To check if the selection is correct, choose Check.
b. To transfer the selection to the row 1 definition, choose Confirm.
You have now defined the first row.
To define the second row for costs, on the Report Painter: Create Report screen, double-click on Row 2.
On the Select element type dialog box:
a. Select Characteristics.
b. Choose
On the Element definition Row 2 dialog box:
a. To include characteristics in the second row of the report, select the desired characteristics in the Available characteristics frame (for example, Account number)
b. Use to transfer the chosen characteristic to the Selected characteristics frame.
c. In From and To, enter the account number(s) you want to include in the row definition (for example, 400000 and 490000).
d. To enter the row heading, choose
On the Text maintenance dialog box:
a. In Short, enter the desired short text (for example, Costs).
b. Choose Copy short text to copy the short text into the Medium and Long text fields.
c. To continue, choose
On the Report Painter: Create Report screen:
a. You can now choose to add further rows with other required characteristics. In this example, you can create a formula in the third row.
b. Double-click on Row 3.
On the Select element type screen:
a. Select Formula as the row element type.
b. Choose
On the Enter Formula screen:
a. Enter the formula for Row 3. You can either type it in or use your mouse and the formula components buttons. If you type the formula, do not forget the spaces. In this example, Y001 and Y002 represent Revenue and Costs respectively.
b. To check the correctness of the formula, choose Check.
c. Choose
On the resulting Text maintenance dialog box:
a. In Short field, enter the text for the formula field (for example, Gross Marg).
b. In Medium and Long fields, enter the required text (for example, Gross Margin).
c. Choose .
You have now defined three rows (Revenue, Costs, and Gross Margin).
Define Columns
Example Task: Defining columns
On the Report Painter: Create Report screen, double-click on the first column, Column 1.
On the Select Element Type (not shown) dialog box:
a. Select Key Figure with characteristics.
b. Choose .
On the Element definition: Column 1 dialog box:
c. In the Basic Key figure field, use the dropdown to select Amount in company code curr.
d. In the Available Characteristics frame, select the desired characteristic for column 1 (for example, Fiscal Year).
If you want to be prompted for the fiscal year at the time of running the report, you must make this a variable instead of a value.
e. Choose to move the desired characteristic to the selected characteristics frame (for example, Fiscal year).
f. Place your cursor in the From value field and select the checkbox to the left under (variable on/off).
g. To view the possible entries for the From field, choose .
h. From the resulting selection dialog box:
 Select a variable from the list of available variables (for example, CYear).
 Choose .
i. On the Element definition dialog box, choose .
j. On the resulting Text maintenance dialog box:
 In Short, enter a text for the column header (for example, Curr Year).
 To copy the short text to Medium and Long text fields, choose the Copy short text button.
 Choose .
Now you have defined the column 1 for your report.
k. Back on the Element definition dialog box, choose Confirm.
On the Report Painter: Create Report screen, define column 2 and all other columns you choose to define. You can define these columns either by:
o Repeating steps for column 1
o Copying columns
o Entering a formula that calculates the difference between columns (for example, between Current Year and Prior Year [variable is Pyear] in a column called Variance)
Adding a column or formula is similar to adding a row formula. After defining the rows and the columns, the screen would appear as follows.
General Data Selection
After you define the rows and columns, define the general data selection screen for the report.
Example Task: Defining the general data selection screen for the report
1. On the Report Painter: Create Report screen, from the menu bar, choose Edit → General data selection.
2. On the Element definition: General data selection screen:
a. From the Available characteristics frame, select the fields to add to the general data selection as shown.
b. Choose to move the selections into the Selected characteristics frame.
c. Enter the values for each field. (For example, the standard ledger for PCA is 8A to 8E and the U.S. company code in IDES is 3000. This example is a year-to-date report, so all 12 periods are in the range. The standard Version in PCA is 0, the Record type for actual dollars is 0, and CO is 2000).
d. To check the selections, choose Check.
e. To create the definition for the general data selection for the report, choose Confirm.
3. On the Report Painter: Change Report screen:
a. To save the report, choose
To include the report into a report group, choose Environment → Assign report group.
1. On the Insert Report in Report Group dialog box:
a. In Report group, enter a report group name (for example, ZTGR).
b. Choose .
2. On the Create report group dialog box, choose Yes to create and assign to a new report group.
Display and Execute the Report
Example Task: Displaying the report you created in the previous steps
1. On the SAP Easy Access screen, either:
o From the navigation menu, choose: SAP menu → Information systems → Ad hoc reports → Report painter → Report → Display.
o In the Command field, enter transaction GRR3 and choose .
2. On the Report Painter: Display Report screen:
a. Double-click on your report.
b. Review the report display.
c. To execute the report, from the application toolbar, choose execute.
On the Selection screen:
a. Enter the variables used to execute the report (for example, Current Year 2000 and Last Fiscal Year as 1999).
b. On the application toolbar, choose execute.
The report appears. You have successfully created a report in Report Painter.
You can also execute the report through the report group (for example, ZTGR).
1. On the SAP Easy Access screen, choose SAP menu → Information systems → Ad hoc reports → Report Painter → Report Writer → Report group → Execute or in the Command field, enter transaction GR55 and choose
2. On the Execute Report Group: Initial Screen:
o In Report Group, use to select a report group.
o Choose .
3. On the next screen, enter appropriate values and choose .
4. On the next screen, from the menu bar, choose:
o Settings → Column attributes to change the column attributes such as changing the column width, setting the scaling factor, and setting decimal place numbering for number display.
o Settings → Summation levels to specify a range of summation levels for which totals will display.
o Settings → Print page format to change the layout of the report output.
5. To transfer the report to Microsoft Excel or Lotus 123, from the application toolbar, choose .
6. On the Options dialog box, select the radio button of your choice and choose . Note that for the report to open in Microsoft Excel or Lotus 123, you need to have these applications installed on your PC.
7. To get back to the original display of the report, select Inactive on the Options dialog box.
Understanding the Report List
After executing a Report Painter report, several additional functions can be applied to the output to make your reports as meaningful as possible. You can:
Sort on each column.
Highlight rows that meet the threshold criteria, for example any amount greater than 6,000.
Drill down from any line item. Drilling down you can access ABAP programs, transaction codes, SAP Queries, drilldown reports, or other Report Painter and Report Writer reports.
Launch SAP Graphics.
Send the report through SAP mail.
Save as an extract to be brought up later.
Expand and collapse rows.
Change the layout settings.
Display the report in Microsoft Excel with office integration.
hope this gives you an idea, and send me an email to [email protected] i will send you a doc on it,
if this was helpful then assign points ..
regards
Jay -
Report Painter - Income Statement Report
Hi SAP Experts,
I'm trying to enhance an existing Income Statement Report (table GLPCT) by adding the PLAN (table GLPCP) columns. Right now, PLAN columns has no data when I execute it.
Report Layout:
Profit & Loss ACT-2007 ACT-2006 PLAN-2007 PLAN-2006
Here is my current settings.
Gen Data Selection: Company Code - 8A-BKRS
Co Area - 0002
Actual Column: <b>Basic Key Figure</b> - BHSL-I
<b>Ledger:</b> 8A
<b>Record Type</b>: 0 (zero)
<b>Fiscal Year</b>: 8A-YEAR (Formula-GLPCT-RYEAR)
<b>Posting Period</b>: 8A-PER (Formula-GLPCT-RPMAX)
<b>Version</b>: 0 (zero)
Plan Column: <b>Basic Key Figure</b> - BHSL-P
<b>Ledger:</b> 8A
<b>Record Type</b>: 1 and 3
<b>Fiscal Year</b>: 8A-YEAR (Formula-GLPCT-RYEAR)
<b>Period</b>: BD-PER (Formula-GLPCP-RPMAX)
<b>Version</b>: 8AVERS1 (Value-GLPCT-RVERS)
My objective is to include PLAN figures againts ACTUAL.
Please give me ideas on how to solve it.
Thank you in advance.
BD
Message was edited by:
Artemio Datu
nullHi
Report Writer functions can be accessed from within the Report Painter.
The difference lies in the GUI of the report painter.
For Report Painter
http://help.sap.com/saphelp_47x200/helpdata/en/66/bc7d2543c211d182b30000e829fbfe/content.htm
For Report Writer
http://help.sap.com/saphelp_47x200/helpdata/en/66/bc7dc143c211d182b30000e829fbfe/content.htm
Refer the following links :
http://www.virtuosollc.com/PDF/Get_Reporter.pdf
http://sap.ittoolbox.com/groups/technical-functional/sap-r3-other/accessing-tables-using-report-painterwriter-98766
http://help.sap.com/saphelp_47x200/helpdata/en/da/6ada3889432f48e10000000a114084/frameset.htm
http://help.sap.com/saphelp_bw31/helpdata/en/66/bc7d2543c211d182b30000e829fbfe/frameset.htm
<b>Reward points for useful Answers</b>
Regards
Anji -
Financial Statement Version in Report Painter
Hi there,
Can anybody please assist. When you have made changes to a FSV, you copy the structure to Report Painter with KE5b - but this is only for GLPCT table (EC-PCA). Which transaction can be used to do the same for cost centres CCSS table?Hi,
1: search SAPNET with search terms "report painter, authorization", guess you find some useful notes.
2: Try T-code KE5B to convert Financial Statement Verison sets to sets that can be used in report painter.
Best regards, Christian
Maybe you are looking for
-
URGETNT: REGARDING Purchase Requsition Approval tables
hi, I am making a report on purchase requsition and i have to display the details of which person has approved it and its date of approval. can anybody tell me which are the tables used in it to display it,example :- 1st Approval - Name of d person
-
Specifying a range of sheets in a formula
I am new to mac and numbers. I have a new iMac with Maverick. Is there a way to sum the same cell in a range of sheets without having to have add all of them separately? In other words, a way to specify a range of sheets? Or, pehaps specify a nam
-
"Time stamp, Response time and Completion time" in CRM_DNO_MONITOR
Hi, We have configured Service desk functionality in Solution Manager 4.0. In CRM_DNO_MONITOR we were able to see all the data except "Time stamp(0), Response time(00:00:00) and Completion time(00:00:00)" of Service desk message. Kindly let us know,
-
I keep getting "missing plug-ins" when trying to open websites applications - what is/are these? I have downloaded Adobe flashplayer and was advised to, but still showing up with this message?
-
hey all, having a problem with a few macs on our network and could use some help. after populating the list of users on our dhcp servers, the macs show up in the "address leases" field with an empty computer name field. all the windows users names ge