473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

refreshing 2D Graphics screen problem

The following program is an applet that reads a number from a file 10
times per second. It needs to be shown graphically.
The file monitors a procesvariable and changes continuously. It is read
okay, and also displays correct on screen (this in the form of a box
that is filled with a certain % corresponding to the value in the file.)

However, the screen only gets the initial value right. The problem I
encounter is that the display is not updated. This is because the method
paint is only performed at init, and for example when I drag the
window (appletviewer) of the screen. That part of the screen is updated.

My question: How can I make sure that every time a value is written,
that the method paint is performed. Can I make a link in class
RemindTask to paint. I tried some things but this did not work. I am a
newbie at Java. Can somebody help me out?

Thanks in advance, Edward Hage

import java.awt.*;
import java.awt.event. *;
import java.awt.geom.* ;
import javax.swing.*;
import java.io.*;
import java.util.Timer ;
import java.util.Timer Task;

public class Shapes extends JApplet {
Timer timer;
Double showvalue;
// some more things //

public void init() {
timer = new Timer();
timer.schedule( new RemindTask(), 0, 100);
}

class RemindTask extends TimerTask {

public void run() {
String d;
d = ReadTopLine();
showvalue = Double.valueOf( d);
}

private String ReadTopLine() {
File inputFile = new File("showfile. txt");
// etc.
return string read from file
//
}

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// etc. draw a box filled with
value showvalue //
}
public static void main(String s[]) {
JFrame f = new JFrame("Shapes" );
f.addWindowList ener(new WindowAdapter() {
public void windowClosing(W indowEvent e) {System.exit(0) ;}
});

JApplet applet = new Shapes();
f.getContentPan e().add("Center ", applet);
applet.init();
f.pack();
f.setSize(new Dimension(550,1 00));
f.show();
}

}

Jul 17 '05 #1
1 2619
Look in RemindTask run method:

"edward hage" <ed**@xs4all.nl > wrote in message
news:40******** *************@n ews.xs4all.nl.. .
The following program is an applet that reads a number from a file 10
times per second. It needs to be shown graphically.
The file monitors a procesvariable and changes continuously. It is read
okay, and also displays correct on screen (this in the form of a box
that is filled with a certain % corresponding to the value in the file.)

However, the screen only gets the initial value right. The problem I
encounter is that the display is not updated. This is because the method
paint is only performed at init, and for example when I drag the
window (appletviewer) of the screen. That part of the screen is updated.

My question: How can I make sure that every time a value is written,
that the method paint is performed. Can I make a link in class
RemindTask to paint. I tried some things but this did not work. I am a
newbie at Java. Can somebody help me out?

Thanks in advance, Edward Hage

import java.awt.*;
import java.awt.event. *;
import java.awt.geom.* ;
import javax.swing.*;
import java.io.*;
import java.util.Timer ;
import java.util.Timer Task;

public class Shapes extends JApplet {
Timer timer;
Double showvalue;
// some more things //

public void init() {
timer = new Timer();
timer.schedule( new RemindTask(), 0, 100);
}

class RemindTask extends TimerTask {

public void run() {
String d;
d = ReadTopLine();
double prev = showvalue;
showvalue = Double.valueOf( d);
if (showvalue != prev) repaint();
}

private String ReadTopLine() {
File inputFile = new File("showfile. txt");
// etc.
return string read from file
//
}

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// etc. draw a box filled with
value showvalue //
}
public static void main(String s[]) {
JFrame f = new JFrame("Shapes" );
f.addWindowList ener(new WindowAdapter() {
public void windowClosing(W indowEvent e) {System.exit(0) ;}
});

JApplet applet = new Shapes();
f.getContentPan e().add("Center ", applet);
applet.init();
f.pack();
f.setSize(new Dimension(550,1 00));
f.show();
}

}

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1614
by: Pudibund | last post by:
Ok, I've spent nearly a week trying to sort what should be an easy task to accomplish but I'm totally flumoxed! I want to do something pretty simple... 1. display image1 2. wait until image1 is drawn to the screen
8
12282
by: Mark Johnson | last post by:
Using: VS 2003 NET C# for Framework and Framework Compact Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on OnMouseMove Problem : The affected drawing Area by Invalidate (or Invalidate(Rectangle)) flickers in a nasty way when repainting. This does not happen in the Solitare (PC + WinCe) Versions a well as in a Card game where I have the C++ Source. The use of an empty OnPaintBackground brings no visable results.
5
20294
by: Vin | last post by:
Hi, I am using the following code to draw whatever the user draws using x,y. // draws lines directly on a winform. CreateGraphics().DrawLine(APen, x, y, OldX, OldY); Now how do I save the drawing on to a bmp file on my harddisk? C# code in this regard would be very helpful. I tried all forums but invain.
6
8165
by: johannblake | last post by:
I am wondering whether it is easy to setup a coordinate system for drawing (using GDI+) that uses meters (or any custom scaling for that matter). Currently, I need to convert from pixels to meters for scaling. This can sometimes get rather complex when you need to take scaling into account or other things like window resizing, scrolling, etc. There is a property called PageUnit which can be set to World. I could not find any examples...
10
1945
by: Galen Somerville | last post by:
Going from VB6 (RAD) to VB2005 (SAD) The documentation always shows graphics drawing in a paint event like Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _ As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint End Sub But my VB6 program draws to the picturebox PictColor from many different
10
2166
by: Paul | last post by:
Hi, I was wondering if anyone knows if it is possible in C# given x,y coordinates of several straight lines to draw these on the screen and then save this as an image file, also adding text to the file like a title? -- Paul G Software engineer.
6
11834
by: NvrBst | last post by:
Hello. I can pInvoke "GetDC" with NULL or "IntPtr.Zero" and get the hDC for the entire screen. I can use the hDC for stuff like "GetPixel" and it works fine. When I try to do the... System.Drawing.Graphics myDC = System.Drawing.Graphics.FromHwnd(IntPtr.Zero); then a "myDC.GetHdc()" and use that with "GetPixel" it doesn't seem to
3
1549
by: Peter Webb | last post by:
When I started my current extremely graphics intensive project, I ignored advice in this ng to use the Paint method, and used the alternate CreateGraphics approach. I thought there were some good reasons for that, which I won't go into. Anyway, there has always been one tiny bug that has annoyed me - the code that draws the initial graphic image into PictureBox1 will only work if wire it up to a button, it doesn't actually do anything if...
11
1501
by: Peter Webb | last post by:
I previously asked about two problems I had with some graphics - the first was that when I drew animation to a picturebox it wouldn't display when the Form loaded. It was suggested to me by everyone that I stop using my own CreateGraphics calls, and override an OnPaint call to do this. As suggested, I created a custom control "drawBox" with an override on its OnPaint. Because I am using manual double buffering, as people suggested it was...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.