Sketch erased in AWT panel
hai
I have a very strange problem:
I am presently working on drawiing a sketches on a panel using a PC tablet...
the scenario is like this:- I have created a Frame and in that I have created a Panel , the screen coordinates of which are scynchronized to those of the PC tablet. At the bottom of the panel there is an OK button.
Now as soon as I draw something on the tablet, I display it on the Panel.
Now when I have completed drawing and when I press ok, I get a dialog box to display a message.
what is the problem now is I see the dialog box, the sketch in the background i.e. on the Panel is erased.
Can any one tell me what can be the problem with my interface......It will be extremely useful for me......thank you
best wishes
You're probably doing the painting in your MouseEventListeren?
If so you have two ways to go, the easier one, and the one I would use, cause it's more "clean".
The easier one is to use double-buffering (read about it on the http://java.sun.com) and do the painting in your EventListeren but do it on the offscreen-buffer, and just call repaint().
The more difficult one is to build a model that holds all the data about the picture, that allows to reproduce it. In your case it would be probably just line coordinates plus colors. And in the EventListeren instead of doing all the painting, just add the new line to the model, and call repaint(). The actuall painting would be done in the paintComponent(Graphics g) method, where you should write a code that would paint your picture based on the data model.
Hope it helps,
Marcin
Similar Messages
-
I was wondering if anybody knows how I would go about drawing onto a Panel as a result of an actionPerformed() call. I got the original code for displaying an image onto the Panel from aresICO on this forum and now I need to be able to click a button on the GUI and have something drawn onto that Panel.
import java.applet.*;
import java.awt.*;
import java.awt.image.ImageObserver;
public class iPane extends Panel {
Image im;
boolean loaded = false;
public iPane () {
Toolkit tk = Toolkit.getDefaultToolkit ();
im = tk.getImage ("Map of Dublin.jpg");
prepareImage (im, -1, -1, this);
public void paint (Graphics g) {
if (loaded)
g.drawImage (im, 20, 20, this);
public void update (Graphics g) {
paint (g);
// if proper values loaded then:
//drawRoute (g);
public void drawRoute (Graphics g) {
g.setColor(Color.red);
g.drawLine(273,51,334,61);
// method takes in values from a file etc.
public synchronized boolean imageUpdate (Image image, int infoFlags,int x, int y, int width, int height) {
if ((infoFlags & ImageObserver.ALLBITS) != 0) {
loaded = true;
repaint();
return false;
else {
return true;
public Dimension getPreferredSize() {
return new Dimension(im.getWidth(this),im.getHeight(this));
public Dimension getMinimumSize() {
return getPreferredSize();
}; // end iPane class
This is a the relevant part of the class which uses an iPane object:
iPane mapPanel;
public void actionPerformed(ActionEvent e)
String buttonLabel = e.getActionCommand();
if (e.getSource() instanceof Button)
if (buttonLabel.equals("Get Directions"))
// What goes in here to draw a line for example?
// How do I call a method from iPane to draw something?
Thanks.Davey,
I don't think your approach is correct. The golden rule of Java graphics is that ALL of painting on a component should be done within the componen'ts paint method(). If you write to iPane from outside the class, then if your iPanel needs to be repainted (because, for example, it got obscured by another window and then unobscured) then the route would not be shown.
You have to think OOD on this.
The route and the image are properties of the of iPanel. The button push requests a change of those properties and display of the results on the screen.
This is what I would do:
1. Create member variables in the class iPanel that define the route.
2. Have a method which sets those variables. This method should call repaint after setting the variables.
2. Maybe have another boolean which says whether the routine is to be displayed or not. This method should call repaint after setting the boolean.
3. Change the paint method to draw the route, if required.
4. In the class that uses iPanel, simply call the methods in iPanel that set the route properties.
5. Change your class name to IPanel. All class names should start with an upper case letter.
e.g.,
private Point start;
private Point end;
private boolean displayRoute
public setRoute(Point newStart, Point newEnd) {
start = newStart;
end = newEnd;
repaint(); // maybe only call if new value is different
public void setDisplayRoute(boolean value) {
displayRoute = value;
repaint(); // maybe only call if new value is different
public void paint(Graphics g) {
g.drawImage( ..... blah
if (displayRoute) {
g.drawline ( .... blah
// Then
onActionPerformed
iPanel.setRoute(new Point(1,2), new Point(3,4)); -
Can't find class when i use java.awt.Panel
I got a Pocket PC with CE 3.0
I made my first PJava application just a few hours ago. And it works fine. But when i introduce a Panel to improve the interface then application fails on the Pocket PC with the error message "could not find class application". When i remove the Panel it works fine again.
I thought that java.awt.* is part of PJava. And even if not i should be able to introduce even a java.lang.* class to the PJava application if i use the JAR.
Any suggestion?you should provide more detail about your deployment procedures.
There are many ways to get this message. AWT in fact is part of pJava and works fine for most of us. So I assume the deployment is the problem. Have you checked the actual content of the JAR? Have you provided a path statement? How do you call your app (shortcut?) -
Saveing contents of awt panel to image file in headless enviroment
Hi im trying create a program that will generate a graph in the form of a PNG file however it must be run in a headless enviroment as its going to be run on a server as part of a larger chain of applications
for graph generation im useing Jgraph2d an opensource libery
the problem im haveing is that the image it produces is blank the program does seem to be drawing something but just a small clump of seemingly random white pixels any help would be apprechiated
p.s. been copy pasteing alot of example code back and forth so please ignore some of the slighly random seeming comments.
public static void main(String[]args){
System.getProperties().setProperty("java.awt.headless", "true");
Toolkit tk = Toolkit.getDefaultToolkit();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println("Headless mode: " + ge.isHeadless());
int width = 800;
int height = 600;
// Create a chart:
Chart2D chart = new Chart2D();
// Create an ITrace:
ITrace2D trace = new Trace2DSimple();
trace.setTracePainter$30c0137f(new TracePainterDisc());
// Add all points, as it is static:
Random random = new Random();
for(int i=100;i>=0;i--){
trace.addPoint(i,random.nextDouble()*10.0+i);
// Add the trace to the chart:
chart.addTrace(trace);
chart.setSize(width,height);
// add the chart to the frame:
Panel panel = null;
// Create an unshown frame
panel = new Panel();
panel.addNotify();
panel.add(chart);
panel.setSize(width,height);
BufferedImage awtImage = new BufferedImage(panel.getWidth(),panel.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics g = awtImage.getGraphics();
panel.printAll(g);
try {
File saveto = new File("e:/graph.png");
ImageIO.write(awtImage, "png", saveto);
} catch (Exception e) {
e.printStackTrace();
}Try hiding the panels first then adding them then show. I know its crazy but I have gotten better performance this way with 1.4.1x. Try it.
current.setVisible(false);
contentPanel.add(current);
current.setVisible(false); -
Drawing Images in awt Panel object
HI,
I need to display an image in a Label.
My project is using awt and not swing. Can anyone help he how to use an setIcon() equivalent in an awt label.
I have tried to work around a bit and remove the label from the parent container and diaplay an image. but that doesn't seem to be working. Any help in this regard would be greatly appreciated.
if( form.equalsIgnoreCase("G")){
Container c = label.getParent();
label.setVisible( false );
Graphics g = c.getGraphics();
Image image = Toolkit.getDefaultToolkit().getImage("abc.gif");
g.drawImage( image, 10, 10, c );
g.dispose();
ThanksHi Subham! Here's an excerpt from the docs for java.awt.Label.
"A Label object is a component for placing text in a container. A label displays a single line of read-only text. The text can be changed by the application, but a user cannot edit it directly."
Ergo, you cannot use an image in lieu of text for a Label object. What you can do, though, is to write your own label class, subclassing from java.awt.Component, exactly as the java.awt.Label does and add the capability of using an image rather than just text.
Hope this helps!
Cheers! -
Unable to resize IClock plug-in which extends java.awt.Panel
I am using an ibm IClock plugin(a javabean) on a JToolBar-this is a clock.The javabean consists of a Canvas on a Panel. I am trying to make the two IClocks smaller so that I can fit a panel to show the date and so that the clocks and date panels are the roughly the same size.
I am unable to resize the Panel. I have tried the following:
1- overriding setPreferredSize. Not sure how to write this code- was getting compilation errors when I did this
public setPreferredSize()
return new Dimension(x,x)
2- invoking setSize(x,x) on the Panel
3- invoking setBounds(x,x,x,x) on the Panel
After Steps 2 and 3 I do a system.out.println and the values I set are returned from the Dimension object. However, the size does not change in the GUI.
I think it may have something to do with the way the layout managers work - and whether they decide to take the preferredSize. From what I can see on the forum, this is a hazy area where short of writing your own layout manager you can't control the LayoutManager very much. But I may be completely wrong, and it may be all much simpler than this.
I am tearing my hair out over this! The only option I can think of is to use an IDE and use a tool to resize the componets. This is the last option. Any ideas would be greatly appreciated.
Thanks
SorayaSorry I may have confused you.Actually I understood you perfectly.
The JToolBar does not need to be resized, the IClock
needs to be resized. The IClock is a Panel.
So what I should do is override getPreferredSize() in
class IClock/Panel?That exactly what I meant, and getMaximumSize() too. -
How can I display an image in AWT Panel
notes: I can't use swing, don't tell me something relate to swing, I need to use pure AWT
Load it with [url http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#createImage(java.net.URL)]Toolkit.createImage or [url http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageIO.html]ImageIO
Subclass Canvas
[url http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20java.awt.image.ImageObserver)]Graphics.drawImage -
I'm sorry that I couldn't figure this out from the search. I tried a few things but none seemed to work.
I have a panel that contains labels. The labels represent objects alive in my system. The Frame watches these objects and updates every second.
I start the panel empty except for a static label at the top that says "objects".
in each loop, I collect object names in an array and create labels for each. I want to replace the current panel content with the new labels. I have tried re instantiating the panel, re writing the panel's paint method to add new labels, but my panel remains looking the same. Can anyone help?
ThanksUsing awt Panels. I didn't want later users to have to have a higher version of java. I'm not married to the version though. Below is the code that I am using...
// Creates the userDisplay panel
// UserDisplay is defined in the Frame
public void createUserDisplay(ArrayList users){
users = users==null?new ArrayList():users;
if(userDisplay != null){
userDisplay.removeAll();
}else{
userDisplay = new Panel();
int labelHeight = 8;
int labelWidth = 24;
userDisplay.setSize(labelWidth,0);
userDisplay.setBackground(Color.white);
userDisplay.setLayout(new java.awt.GridLayout(0,1));
Label usersHeader = new Label();
usersHeader.setSize(labelWidth,labelHeight);
usersHeader.setBackground(Color.white);
usersHeader.setFont(BIG);
usersHeader.setText("USERS");
usersHeader.setBounds(0,labelWidth,labelHeight,labelWidth);
userDisplay.add(usersHeader);
for(int a = 0; a < users.size(); a++){
Label L = new Label();
L.setFont(normal);
L.setBounds(0,labelWidth + (a * labelHeight),labelHeight,labelWidth);
L.setBackground(
((SimpleChat.User)users.get(a)).status == 1
Color.yellow
Color.white
L.setSize(labelWidth,labelHeight);
L.setText(((SimpleChat.User)users.get(a)).name);
userDisplay.add(L);
System.out.println("Added " + L.getText());
} -
AWT PopupMenu not showing Chinese Characters
Hi all.
I have a mostly Swing application that must display English and Chinese characters. Changing the Swing components has been easy, however I am having problems changing an AWT PopupMenu that i use in combination with the new TrayIcon features of Java 6. TrayIcon requires an awt PopupMenu, so i cannot use a Swing JPopupMenu even if i wanted to.
The problem is that instead of the correct words i am getting just empty squares, which seem to indicate a problem. I have tried setting the font to "SimSun" but this made no difference.
I also tried this hack to use a JPopupMenu with Trayicon
http://weblogs.java.net/blog/ixmal/archive/2006/05/using_jpopupmen.html
This correctly showed the Chinese characters but it threw up lots of 'class cast' exceptions.
My ideal solution would be to fix the problems with PopupMenu as apposed to fixing the class cast exception errors with the JPopMenu hack.
Would anyone know why i cannot display Chinese characters in a AWT PopupMenu? have i missed something?
Thanks
Stevenhi!
check this out
package com.ani;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JLabel;
public class showHindi extends Panel
public showHindi()
setLayout(new BorderLayout());
String unicodeText = "\u0928\u092e\u0938\u094D\u0924\u0947";
Font fn = new Font("Arial Unicode MS", Font.PLAIN, 32);
Label lblText = new Label(unicodeText) {
@Override
public void paint(Graphics g)
//super.paint(g);
g.clearRect(0, 0, getWidth(), getHeight());
String str = getText();
g.drawChars(str.toCharArray(), 0, str.length(), 0, 30);
//System.out.println(getText());
lblText.setFont(fn);
JLabel lblText1 = new JLabel(unicodeText);
lblText1.setFont(fn);
add(lblText, BorderLayout.NORTH);
add(lblText1, BorderLayout.SOUTH);
public static void main(String[] args)
Frame frm = new Frame("Test Hindi");
frm.add(new showHindi());
frm.setSize(600, 400);
frm.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e)
System.exit(0);
frm.setVisible(true);
}this is working in my machine. i have used JLabel and Label both to just show you the difference. there is a flickering bug because of rendering, i hope you can manage that.
regards
Aniruddha -
hello!
i create a panel with several small panels on it, so it is too big to display in my window. therefore i want to have it a scrollpane. this way:
JPanel jp = new JPanel();
jp.setLayout(new BoxLayout(jp,BoxLayout.Y_AXIS));
for(int p=1;p<12;p++){
posten rlist1 = new posten(p); // "posten" is a small panel
jp.add(rlist1);
JScrollPane sp =new JScrollPane();
sp.setViewportView(jp);
jPanel10.add(sp);jpanel10 has the scrolls on it, to scroll jp.. but the panel jp which is too big, laps over at top and bottom.
hard to explain perhaps, here is a picture:
http://www.cds-server.de/pub/jpanel.jpg
what can i do to make it hide the too big parts?ok, it took me the hole day to find out that to reproduce this behavior it is necessary
to have the underlaying panel with "free design",
the next panel is with boxlayout . and there is the mess.
therefore the code is not very short, more long, sorry for that,
but it is the shortest way to show my problem:
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class qqqq extends javax.swing.JFrame {
public qqqq() {
initComponents();
JPanel jp = new JPanel();
jp.setLayout(new BoxLayout(jp,BoxLayout.Y_AXIS));
for(int p=1;p<12;p++){
posten rlist1 = new posten(p);
jp.add(rlist1);
jp.validate();
JScrollPane sp =new JScrollPane(jp);
jPanel2.add(sp);
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
.addContainerGap())
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
.addContainerGap())
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(75, Short.MAX_VALUE))
pack();
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new qqqq().setVisible(true);
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
//******inner class with panel****//////////
class posten extends java.awt.Panel {
public posten(Integer p) {
initComponents();
jLabel1.setText(p.toString());
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
setLayout(new java.awt.BorderLayout());
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.setMaximumSize(new java.awt.Dimension(32767, 8));
jLabel1.setText("Posten");
jPanel1.add(jLabel1);
jPanel1.add(jTextField1);
jPanel1.add(jTextField2);
add(jPanel1, java.awt.BorderLayout.CENTER);
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
} -
I have read previous posts about this, and read article 107437 on "How to zero all data on disk", but am still unsure what to do. I am a novice, so it may be the terminology. Anyway, I apologize if this has already been explained and I just dont get it.
I teach art and have 12 networked PowerPc G4s (with 512 MB RAM). They are laden with the previous teacher's passwords (which I dont know), and are currently running in OS X 10.1. We use Illustrator and Photoshop, but the Photoshop is an older version, using Classic. They have been slow. Alas, we have gotten the discs to install 10.3, and will be receiving the latest Photoshop.
What I would like to do is get rid of everything on the computers and start from scratch to install my new OS and new applications. I dont need anything that is on the comptuers now, as I still have the discs for applications I want to keep.
I have gotten the impression that erasing is bad and/or complicated, and that "zero"ing it would be better, but the article on "How to zero..." says that it makes data "less recoverable". What does that mean? Will it still be there taking up space? Will the old teacher's passwords still be there? Will the networking be compromised?
I really appreciate any help anyone could offer.
PowerPC G4 512MB RAM Mac OS X (10.1.x) Second Computer: iMac G5 1GB RAM
PowerPC G4 512MB RAM Mac OS X (10.1.x) Second Computer: iMac G5 1GB RAMMy goodness, Leah, so many questions!
Let's see if we can cover them all.
1. Erase vs. zeroing. For what you want to do erasing the disk will be fine. Zeroing does a more thorough job, especially if there are disk problems. We will come to the process later.
2. Both zeroing and erasing will destroy your data. It is important to backup the User Folder to avoid loss of data.
3. If you decide to Archive and Install the previous teacher's passwords will still be there, although you can create a new user account and get around that.
If I have missed any of your questions, please post back with them.
Here are some suggestions on installation. You will note there is an option to zero. If you want to erase only, skip the Option button, and directly to Erase:
Panther: Archive and Install
If you do not have a Full Retail Version you can get one on eBay relatively inexpensively.
If you have the right disks here is what you do.
1. Warning: Although we will use Archive and Install there is always a risk something can go wrong. As a precaution back up your User Folder and any apps you can't afford to lose.
2. Check to see if you have the latest Firmware Update
http://docs.info.apple.com/article.html?artnum=86117
3. Boot from the install disk holding down the C key.
4. Once booted go to the Installer Menu and open Disk Utility.
5. Run Repair Disk. If there are problems, run it until no problems are reported. If it reports that it can't repair the problems you might need TechTool Pro or Disk Warrior.
6. While still in Disk Utility run Repair Permissions.
7. Quit Disk Utility and open the Installer.
8. Choose the option to Archive and Install. This saves your data in a Previous Systems folder, which you can retrieve after installation.
9. You might want to Customize and deselect Foreign Language Translations and Additional Printer Drivers to save Hard Drive space.
10. Proceed with installation.
11. After installation is complete computer will restart. Follow prompts and set up computer.
Open Disk Utility (Applications > Utilities > Disk Utility) and Repair Permissions.
12. Go online and download updates, or go to Software Update under the Apple Menu and update your OS.
13. Transfer your User Folder from Previous Systems folder.
NOTE (below):
To do a clean install:
Follow steps 1 through 4 above.
a. In Disk Utility select your HD in left panel and Erase in main panel.
b. Be sure Volume Format is Mac OS Extended and the checkbox Mac OS 9 Drivers Installed is checked.
c. Select Options at bottom left in Erase panel. (
WARNING! This procedure will erase the contents of your entire HDD. Be sure you back up anything you cannot afford to lose!
Select option to zero all data. Click OK. Click Erase.
This process will take a while, so this is a good time to take a long walk or call your mother
d. After HDD is erased resume at No. 7 above.
Post back with any questions or comments.
Good luck.
cornelius
PB G3 Pismo400, 100 GB 5400 Toshiba internal, 1 GB RAM Mac OS X (10.3.9) Beige G3 OS 8.6 -
Panel isn't expanding with the window
Hey,
I am writing a Sudoku program, and well I haven't really done anything yet. All it does is draw the board (9x9 grid) on a Panel, then the panel is added to the Applet. Thing is, the Applet is set to a 550x550 size, but the Panel doesn't expand with it. It's stuck at the default(?) size. The TextFields (the grid) expand with the window, so only a few are shown on the screen. A screenshot can be found here -> http://i46.tinypic.com/2wnzqtu.png
Here's the code:
package sudoku;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class PlaySudoku extends Applet implements ActionListener
static final int FRAME_WIDTH = 550;
static final int FRAME_HEIGHT = 550;
static final int BOARD_ROWS = 9;
static final int BOARD_COLUMNS = 9;
static final int BOARD_WIDTH = 500;
static final int BOARD_HEIGHT = 500;
TextField[][] grid = new TextField[BOARD_ROWS][BOARD_COLUMNS];
Panel board = new Panel(new GridLayout(BOARD_ROWS, BOARD_COLUMNS));
public void init()
this.setLayout(new BorderLayout());
this.setSize(FRAME_WIDTH, FRAME_HEIGHT);
for (int i = 0 ; i < BOARD_ROWS ; i++)
for (int j = 0 ; j < BOARD_COLUMNS ; j++)
grid[i][j] = new TextField();
board.add(grid[i][j]);
this.add(board, BorderLayout.CENTER);
public void actionPerformed(ActionEvent e)
}Thanks,
Coh3nOnly just checked the image.
- What OS is that?
- What is the exact (copy/pasted in code tags) HTML used for the applet viewer?
Or perhaps - run this variant of your code and report back.
// <applet code='PlaySudoku' width='650' height='250'></applet>
import java.applet.Applet;
import java.awt.*;
public class PlaySudoku extends Applet
static final int BOARD_ROWS = 9;
static final int BOARD_COLUMNS = 9;
TextField[][] grid = new TextField[BOARD_ROWS][BOARD_COLUMNS];
Panel board = new Panel(new GridLayout(BOARD_ROWS, BOARD_COLUMNS));
public void init()
this.setLayout(new BorderLayout());
for (int i = 0 ; i < BOARD_ROWS ; i++)
for (int j = 0 ; j < BOARD_COLUMNS ; j++)
grid[i][j] = new TextField();
board.add(grid[i][j]);
this.add(board, BorderLayout.CENTER);
// always a good idea
validate();
System.out.println("Size: " + getSize());
System.out.println("os.name: " + System.getProperty("os.name"));
System.out.println("java.vendor: " + System.getProperty("java.vendor"));
System.out.println("java.version: " + System.getProperty("java.version"));
System.out.println("java.vm.version: " + System.getProperty("java.vm.version"));
}Here are the results I'm getting, with no odd sizing artifacts.
andrew@pc1:/media/disk/proj$ javac PlaySudoku.java
andrew@pc1:/media/disk/proj$ appletviewer PlaySudoku.java
Size: java.awt.Dimension[width=650,height=250]
os.name: Linux
java.vendor: Sun Microsystems Inc.
java.version: 1.6.0_14
java.vm.version: 14.0-b16
andrew@pc1:/media/disk/proj$ Note that on this OS/SDK, the appletviewer can parse an applet element out of the first (commented) line of the Java source file. -
Handling FocusEvents in subclassed Panel.
I've created some Button objects in AWT that look like
the Swing Metal Button. The funtionality is fine, the
MouseEvents effect the paint(Graphics) method, and
everything looks and works great... except for the
focus.
How do I make this Object aware that it has the focus?
I want it to draw a dark outline around itself (just like
a regular awt.Button) when it gets the Focus. I also want
it to listen for KeyEvents when it has focus so you can
use the Space Bar to activate it.
I tried implementing FocusListener and catching
focusGained(FocusEvent), but nothing happens.
In my application, it doesn't behave like a Focusable
component.
How do I make it focusTraversable?
Thanks,
Rob.Thanks Raginald, but that was not the problem.
I am extending an awt.Panel and overriding the
paint(Graphics), I call an init method from the
constructor. In the init() method I add the
MouseListener and the FocusListener. The
Focus event never gets fired. The application
I have added this "Button" to doesn't seem to
recognize that it is a focus-able component.
When I tab through the components, my "Buttons"
never get the focus. I overrided isFocusTraversable(),
but that had no effect either.
Is it possible that the mouseEvents I'm capturing to
handle the entered and clicked effects are masking
the focusEvents?
Any ideas?
Rob. -
Pass a panel to other constructer
the problems is this:
public class User
Panel p;
public User(Panel p)
this.p=p;
public class Gui extends Applet
private Panel pan;
public void init()
pan=new Panel();
User u=new User(pan);
the compiler give me:
cannot resolve symbol
symbol:constructer user(java.awt.panel)
location:class user
User u=new User(pan)
what is the problem?
my user class is in the same directory
when i write:
User u=new User();everything is wright without error
why i cant pass a panel to the user constructer when that constructer except to get the panel?The following code compiles with no errors on my system.
import java.awt.Panel;
public class User {
Panel p;
public User(Panel p) {
this.p=p;
import java.awt.Panel;
import java.applet.Applet;
public class Gui extends Applet {
private Panel pan;
public void init() {
pan=new Panel();
User u=new User(pan); -
How to add a scroll pane for a panel.
Hi
i have a panel with some images drawn . i want a scroll pane added to this panel.
I tried adding it but failed.
Any suggestions please (
here is my code.
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
class frame extends JFrame
public frame()
JScrollPane pane=new JScrollPane();
setContentPane(new DrawClass());
setSize(500,300);
setBounds(200,300, 100, 500);
setVisible(true);
public class DrawClass extends JPanel implements ActionListener {
public DrawClass(){
public void paintComponent(Graphics g){
super.paintComponent(g);
String [] Filenames={"im3","im4","im5","im6"};
int imgX = 0;
int imgY = 10;
Toolkit toolkit = Toolkit.getDefaultToolkit();
Integer[] intArray = new Integer[Filenames.length];
for (int i = 0; i < Filenames.length; i++)
intArray[i] = new Integer(i);
if (Filenames[i] != "" )
//XMLFileParser r=new XMLFileParser();
Image img =toolkit.getImage( "/home/swathi/Desktop/Images/"+ Filenames[i]+ ".jpg" );
g.drawImage (img, imgX, imgY, this);
imgY=imgY+100;
else
System.out.println("NO file Found");
public static void main(String[] args){
frame f =new frame();
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
can you please help me in this code .....
DrawClass.
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
class frame extends JFrame
public frame()
setContentPane(new DrawClass());
setSize(500,300);
setBounds(200,300, 100, 500);
setVisible(true);
public class DrawClass extends JPanel implements ActionListener {
public DrawClass(){
public void paintComponent(Graphics g){
super.paintComponent(g);
String [] Filenames={"im3","im4","im5","im6"};
int imgX = 0;
int imgY = 10;
Toolkit toolkit = Toolkit.getDefaultToolkit();
Integer[] intArray = new Integer[Filenames.length];
for (int i = 0; i < Filenames.length; i++)
intArray[i] = new Integer(i);
if (Filenames[i] != "" )
//XMLFileParser r=new XMLFileParser();
Image img =toolkit.getImage( "/home/swathi/Desktop/Images/"+ Filenames[i]+ ".jpg" );
g.drawImage (img, imgX, imgY, this);
imgY=imgY+100;
else
System.out.println("NO file Found");
public static void main(String[] args){
frame f =new frame();
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ListClass
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.dnd.*;
import javax.swing.*;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.awt.Toolkit;
import javax.swing.*;
import org.w3c.dom.Node;
public class ListClass extends JPanel{
ListClass(){
DrawClass d=new DrawClass();
My question is how i can call a method of DrawClass which contains the drawn images ; in the List Class.
its very urgent please.....
Maybe you are looking for
-
Sorry for the "spammy" post, but I am hoping someone from Adobe will notice: http://techfeed.net/blog/index.cfm/2007/8/22/Open-Letter-to-Tim-Buntel The basic idea of the letter, is that I feel Adobe could do a LOT more to market ColdFusion, and I giv
-
T520 with Optimus - Can't install Intel Graphics Driver in XP
Hello, I have T520 with Optimus FHD screen. I have XP installed in my Ultrabay HDD. I understand that XP doesn't support Optimus and that I must go to BIOS and choose either Discrete or Integrated. OPTION 1 (Discrete Only) Which someone what works:
-
HI In F-53 after entering and simulate the data can't we chenge the document type without going back to beginning??? Pls advice...................... Thanx.
-
Cannot change price unit in POs
Hi all! I have a PO with an item like this: Price = 125 Currency = USD Price unit (per) = 1 The user would like to change the field "Price unit (per)" to 10. But when we change the value is reset to 1. We've tried to change the value in the Item Over
-
Nokia phone model and text to speech software
What models of nokia support text to speech software ?Should the software be installed in the phone memory or on the memory card? What site do I download the text to speech software from? My budget is around Rs 7000