background and foreground color is not changing in full screen window


why my background and foreground color is not changing\t

import java.awt.*; import javax.swing.*; public class mainScreen extends JFrame{ public static void main(String args[]) { DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN); mainScreen ms = new mainScreen(); ms.run(dm); } public void run(DisplayMode dm) { setBackground(Color.PINK); setForeground(Color.GRAY); setFont(new Font("Arial", Font.PLAIN, 24)); Screen s = new Screen(); try{ s.setFullScreen(dm, this); try{ Thread.sleep(5000); }catch(Exception e){} }finally{ s.restoreScreen(); } } public void paint(Graphics g) { g.drawString("This is FullScreen", 200, 200); } }
Posted On: Wednesday 26th of September 2012 01:50:40 AM Total Views:  88
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Change icon color dinamically

! I'm trying to create a JFrame with 3 circles inside it and make it work like a traffic light. I've created a separate class for lights, but I can't make them change colors dinamically, because once the icon has been drawn, I can't change it's color anymore Should I give up this idea or there is a way to get it done package trafficlight; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import javax.swing.Icon; public class Light implements Icon { private int size; private Color colorOff = Color.BLACK; private Color currentColor = Color.BLACK; private Color colorOn; private int delay; public Light(Color color, int size, int delay) { this.colorOn = color; this.size = size; this.delay = delay; } public void switchLight(boolean turnOn) { //here I want to make my Light to change its color } @Override public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(currentColor); g.drawOval(x, y, size, size); g.fillOval(x, y, size, size); } @Override public int getIconWidth() { return size; } @Override public int getIconHeight() { return size; } public int getDelay() { return delay; } public void setDelay(int delay) { this.delay = delay; } }
VIEWS ON THIS POST

109

Posted on:

Thursday 20th September 2012
View Replies!

color help

Folks, Below is a code I have been writing on my own (well a modification from what online version read). The error has been highlighted. import javax.swing.JOptionPane; public class playwithrange { public static void main(String[] args) { String color ; color= JOptionPane.showInputDialog("Choose between green, black and white"); switch (color){ case green: System.out.println("You are a green person"); break; default: System.out.println("Eh whatever"); } } }
VIEWS ON THIS POST

95

Posted on:

Thursday 20th September 2012
View Replies!

Problem in changing title of frame of outer class by inner class button

import java.awt.*; import java.awt.event.*; class setTittleTest extends Frame implements ActionListener // outer class { Button b; setTittleTest() // main frame { b = new Button("Main"); add(b); b.addActionListener(this); setSize(450,450); setTitle("Yes"); setVisible(true); } public void change() { setTitle("tittle changed"); } class newtitle extends Frame implements ActionListener // inner class { Button b1; newtitle() { setSize(300,120); setTitle("inner class Dialogue"); b1 = new Button("click"); add(b1); b1.addActionListener(this); setVisible(true); } public void actionPerformed(ActionEvent e1) { change(); // here can be a better approach then this } } // inner class end public void actionPerformed(ActionEvent e) { newtitle nt = new newtitle(); } public static void main (String[] args) { setTittleTest t = new setTittleTest(); } }
VIEWS ON THIS POST

118

Posted on:

Friday 21st September 2012
View Replies!

how to get colored line to differentiate text field array in swing

I have developed one frame on which I used GridBagLayout to arrange textfields of 12X12. i.e., total 144 textfields on frame. Now I want to differentiate these text fields with colored line after each 3 columns and three rows as shown in the following diagram. I shouldn't change the names of that text fields, because I interrelated those text fields using their names as jt[0][0], jt[0][1]......jt[6][2]........ and So on.I tried in many ways, but I couldn't find the solution. Please suggest. Below is the some part of my code.
VIEWS ON THIS POST

187

Posted on:

Friday 21st September 2012
View Replies!

Program color scheme controlled by a Colors class: object or enum?

I'm writing a rather large program with lots of classes and potentially lots of JFrames. Could I have one class devoted to establishing the primary selection of colors that will be repeated throughout the program That way, rather than remembering each color definition, I can just code something like Colors.TitleFont to represent the color of the title of each window, and Colors.InputPanelBg to represent the background of any input window. I have not found examples of this on-line, but it seems reasonable. Would a Colors object or an Enum work for this Here is my attempt, but Eclipse says "The constructor GSCOLORS(String) is undefined." import java.awt.Color; public enum GSCOLORS { InputPanelA("0xa29292"), InputPanelB("0x92a292"); private Color col; GSCOLORS(Color colorId) { col = colorId; } public Color getCol() { return col; } }
VIEWS ON THIS POST

96

Posted on:

Friday 21st September 2012
View Replies!

having problems with setting the color of a buffered Imaghe

I created a buffered image in my programme and I want it to have a green (orany color other than black)background however i have been unable to get it to change from black to any other other color.hers the code i have been working with .
VIEWS ON THIS POST

237

Posted on:

Friday 21st September 2012
View Replies!

Creating a BufferedImage of an offscreen JButton (or other Component)

I am trying to create a Swing component that, in its paint() method, draws a possibly scaled version of JButtons and other Components. It would not be appropriate to physically place those Components inside the original Component because the layout managers would not do the type of "scaling" I am looking for - I would like the text/image inside to also be scaled. What I am getting are empty gray boxes of the appropriate sizes. If I use JButtons I don't see the the rounded corners or the button text, and if I use a JPanel with a JLabel within I don't see the label's text. The problem appears to be with my use of the Component.createImage() function, but I can't figure out why. Here's the basic code: public class PreviewPanel extends JPanel { BufferedImage backgroundImage = null; ArrayList components = new ArrayList(); // These are the components that need to be drawn/scaled. public BufferedImage getBackgroundImage() { return backgroundImage; } public void setBackgroundImage(BufferedImage backgroundImage) { this.backgroundImage = backgroundImage; repaint(); } public void addComponent(Component component) { components.add(component); add(component); // If we don't add the Component to ourselves we'll get a null image from createImage() later. repaint(); } public void removeComponent(Component component) { components.remove(component); remove(component); repaint(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); // Prepare for image scaling. Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // Calculate scaling factor. Use 1 for this example. double scale = 1; // Using parent's full width/height and left/top for this example. int width = getWidth(); int height = getHeight(); int left = 0; int top = 0; if (backgroundImage != null) { // Draw a scaled and centered version of the background. int bgWidth = (int) scale * backgroundImage.getWidth(); int bgHeight = (int) scale * backgroundImage.getHeight(); int bgLeft = (width - bgWidth) / 2; int bgTop = (height - bgHeight) / 2; g2.drawImage(backgroundImage, bgLeft, bgTop, bgWidth, bgHeight, null); } // Draw a scaled version of each of the components. for (Component component : components) { // For the sake of the example let's assume this was already initialized appropriately. Rectangle bounds = component.getBounds(); // ** This here is the possible location of the problem - I get just an empty gray box. BufferedImage componentImage = component.createImage(bounds.width, bounds.height); // Draw a scaled version of the Component. Scaling works appropriately. g2.drawImage(componentImage, (int)(left + (scale * bounds.x)), (int)(top + (scale * bounds.y)), component.bounds.width, component.bounds.height, null); } } }
VIEWS ON THIS POST

116

Posted on:

Saturday 22nd September 2012
View Replies!

How to make scrolling area bigger. i.e. increase window size?

I know that you use either the JPanel revalidate() or the JScrollPane revalidate(). Which one I don't know. However, I did both and still it's not resizing. I know that there's some other line of code I needed but can't recall what it was. I thought it might be the JFrame pack() method, but that didn't do it either.
VIEWS ON THIS POST

192

Posted on:

Saturday 22nd September 2012
View Replies!

Change Background color on button Click

Hi I want to change Background color of Jpanel and its font on button click. Can anyone tell me what i am doing wrong Here is the code: import java.applet.*; import java.awt.*; import java.awt.image.BufferedImage; import java.awt.event.*; import javax.swing.*; public class test3 extends Applet { JPanel c; JScrollPane s; Button connect; Panel controls; Color back,fore; public void init() { back = Color.black; fore = Color.white; setBackground(Color.darkGray); setLayout(new BorderLayout()); s = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //s.setSize(100, 100); add("Center",s); c = new myCanvas11(this); s.setOpaque(false); s.setViewportView(c); //s.add(c); c.setSize(1000, 16000); add("North", controls = new Panel()); controls.setLayout(new FlowLayout()); controls.add(connect = new Button("Change Color")); } public void start() { // s.setScrollPosition(100, 100); } public boolean action(Event e, Object arg) { back = Color.magenta; fore = Color.blue; //setBackground(back); //invalidate(); //repaint(); c.setBackground(back); c.repaint(); //s.getViewport().setBackground(back); // s.getViewport().repaint(); //c.repaint(); c.setFocusable(true); return true; } } class myCanvas11 extends JPanel implements KeyListener { Image buffImage; Graphics offscreen; boolean initDone = false; int chw, chh; // size of a char (in pixels) int chd; // offset of char from baseline int width, height; // size of applet (in pixels) int w, h; // size of applet (in chars) Font fn; Graphics gr; int nh, nw; test3 owner; static int counter = 0; myCanvas11(test3 t) { super(); owner = t; nh = 16000; nw = 1000; this.setOpaque(true); this.setFocusable(true); addKeyListener(this); } public void reshape(int nx, int ny, int nw1, int nh1) { if (nw1 != width || nh1 != height) { width = nw; height = nh; gr = getGraphics(); fn = new Font("Courier", Font.PLAIN, 11); if (fn != null) gr.setFont(fn); FontMetrics fnm = gr.getFontMetrics(); chw = fnm.getMaxAdvance(); chh = fnm.getHeight(); chd = fnm.getDescent(); // kludge for Windows NT and others which have too big widths if (chw + 1 >= chh) { chw = (chw + 1) / 2; } // work out size of drawing area h = nh / chh; w = nw / chw; buffImage = this.createImage(nw, nh); offscreen = buffImage.getGraphics(); //offscreen.setColor(Color.black); //offscreen.fillRect(0, 0, nw, nh); offscreen.setColor(Color.blue); offscreen.setFont(fn); if (initDone) offscreen.drawString(" World!", 0, 50); else offscreen.drawString("khushbu", 2, 50); initDone = true; offscreen.drawImage(buffImage, 0, 0, this); } super.reshape(nx, ny, nw, nh); } public void paint(Graphics g) { // if (!initDone) // initpaint(g); // else g.drawImage(buffImage, 0, 0, this); //g.drawImage(buffImage, 0, 0, owner.back, this); } public void update(Graphics g) { g.drawImage(buffImage, 0, 0, this); super.update(g); //g.drawImage(buffImage, 0, 0, owner.back, this); } public void initpaint(Graphics g) { try { nh = getHeight(); nw = getWidth(); gr = getGraphics(); fn = new Font("Courier", Font.PLAIN, 11); if (fn != null) gr.setFont(fn); FontMetrics fnm = gr.getFontMetrics(); chw = fnm.getMaxAdvance(); chh = fnm.getHeight(); chd = fnm.getDescent(); // kludge for Windows NT and others which have too big widths if (chw + 1 >= chh) { chw = (chw + 1) / 2; } // work out size of drawing area h = nh / chh; w = nw / chw; buffImage = this.createImage(nw, nh); offscreen = buffImage.getGraphics(); //offscreen.setColor(Color.black); //offscreen.fillRect(0, 0, nw, nh); offscreen.setColor(Color.white); offscreen.setFont(fn); if (initDone) offscreen.drawString(" World!", 0, 50); else offscreen.drawString("khushbu", 2, 50); initDone = true; g.drawImage(buffImage, 0, 0, this); } catch (Exception e) { e.printStackTrace(); } } /** Handle the key typed event from the text field. */ public void keyTyped(KeyEvent e) { } /** Handle the key pressed event from the text field. */ public void keyPressed(KeyEvent e) { String s; offscreen.setColor(owner.fore); offscreen.setFont(fn); for (int i = counter; i < counter + 25; ++i) { s = Integer.toString(i); offscreen.drawString(s, 3, i * chh); offscreen.drawLine(10, i * chh, 160, i * chh); } //owner.s.setScrollPosition(0, counter * 16); counter = counter + 25; repaint(); } /** Handle the key released event from the text field. */ public void keyReleased(KeyEvent e) { } public boolean keyDown(Event e, int k) { String s; offscreen.setColor(owner.fore); offscreen.setFont(fn); for (int i = counter; i < counter + 25; ++i) { s = Integer.toString(i); offscreen.drawString(s, 3, i * chh); offscreen.drawLine(10, i * chh, 160, i * chh); } //owner.s.setScrollPosition(0, counter * 16); counter = counter + 25; repaint(); return true; } }
VIEWS ON THIS POST

122

Posted on:

Saturday 22nd September 2012
View Replies!

Change canvas background colour at button click

I am developing Java applet, which have canvas in it. I want to change background color of canvas at one button click. i have changed it using c.offscreen.setColor(back); c.offscreen.fillRect(0, 0, c.getWidth(), c.getHeight()); c.repaint();
VIEWS ON THIS POST

139

Posted on:

Saturday 22nd September 2012
View Replies!

Trouble with JEditorPane changing colors with styles

I'm using Styles to change the color of my reserved words, but its changing incorrectly, its changing right when I type in the first line but in the next lines only part of the word is changed, what is wrong with my code\t the problem! Uploaded with ImageShack.us this is the code -> public void doFindText(String find) { SimpleAttributeSet bluAttr = new SimpleAttributeSet(); StyleConstants.setForeground(bluAttr, Color.BLUE); SimpleAttributeSet GreenAttr = new SimpleAttributeSet(); StyleConstants.setForeground(GreenAttr, Color.GREEN); int nextPosn = 0; if (!find.equals(findText) ) // *** new find word findPosn = 0; // *** start from top nextPosn = nextIndex( Ed_Prog.getText(), find, findPosn, false); if ( nextPosn >= 0 ) { //Ed_Prog.setSelectionStart( nextPosn-1 ); // position cursor at word start //Ed_Prog.setSelectionEnd( nextPosn + find.length() ); if(find.equalsIgnoreCase("programa")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn,nextPosn + find.length()+1, bluAttr, false); }else if(find.equalsIgnoreCase("string")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } else if(find.equalsIgnoreCase("inteiro")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } else if(find.equalsIgnoreCase("real")){ Ed_Prog.getStyledDocument().setCharacterAttributes(nextPosn-1,nextPosn + find.length()+1, GreenAttr, false); } findPosn = nextPosn + find.length()+1; // reset for next //search findText = find; // save word & case nextPosn = 0; } else { findPosn = nextPosn; // set to -1 if not found //JOptionPane.showMessageDialog(this, find + " not Found!" ); } }
VIEWS ON THIS POST

123

Posted on:

Saturday 22nd September 2012
View Replies!

closing a window and returning a value from a subroutine

I am relatively new to Java and this is my first posting here. I'm trying to adapt a program I wrote years ago in Visual Basic. This is one class that is called by another to prompt the user to select the type of variable (the data are read in elsewhere in the larger program) from a radio button list (mine has 10 choices; I limited it to 3 here). Once the radio button is set, they click on the JButton ("Done") to pass the varType back to the calling subroutine and close the JWindow (I preferred the JWindow to the dialog box choices because I don't want the user to be able to "X" out of this dialog. Two problems are preventing this from compiling. The first is where to put the Return statement (currently in the button's ActionListener class). The second is where or how to close the JWindow (I'm using "dispose()", currently in the subroutine called by the ActionListener). I left out the imports to save space.
VIEWS ON THIS POST

68

Posted on:

Saturday 22nd September 2012
View Replies!

White screens on some windows

We have a multi-window Java application that is able to get itself into a state where it renders white screens. This application makes some external network connections and based on data that's sent over those connections updates the UI, and opens and closes various windows. Naturally this only happens on the production machine, and only when nobody is around to investigate the problem as it is happening. The pattern that has been established via customer reports is that it will not happen for a couple weeks then will happen a few times frequently, eg 2x in 50mins. The customer has been killing the software and restarting the application when it starts showing white screens. We have caught it in action exactly once, and it resolved itself after about 20 minutes. We have three windows that this has been confirmed to happen on. The only thing that these windows have in common is that a) they are triggered by data sent in over the network connection, and b) they are windows that are opened and closed constantly. One of these windows renders two JTextFields, the rest of the screen is blank (and the two fields that are rendered are drawn in the middle of the frame creation). For case A, each window refreshes based on a different type of packet. In one case it is an entirely different socket that is sending the packets. There are three other windows (always open) that are responding to the same data and updating the UI, so we know the packet data is getting around. Case B may leave more clues; it seems to hit a trigger where any windows opened after a certain point are rendered with a white screen. Windows that are already opened continue to update their displays but new windows are useless. We can't confirm this absolutely because the UI goes click-unresponsive; the only windows that can be opened are those that are triggered by the network data, and we can't close any windows either. (Interestingly enough, the customer has reported that there is one set of buttons on a working/rendered window that does work). The CPU usage for the Java process spikes according to performance monitor logs and remains high as long as the white screens are appearing. Interestingly, the Task Manager does not reflect these numbers, reporting 5-10% CPU while the performance monitor reports >100% (dual core pc, max usage = 200%) The heap is capped at 512MB. While displaying white screens, the memory usage as reported by task manager is 186MB, after it resolves itself this jumped to 271MB. Both numbers are what I would consider typical for this application. The software was installed last year, and was working fine until several weeks after an update. The software was compiled under JDK6 and is running on JRE 1.6.0_33. The computer is a Windows 7 Professional x86 OS, dual monitors. I understand it has onboard video and there are generic drivers installed. I haven't been able to find OEM updates for these drivers (the monitors are Samsung E2220X) of our GUI updates are done on the event thread. windows are shown and hidden on the event thread. Because the problem resolves itself (and the windows do not share objects) I do not think this is a deadlock. I've added the Sun options for rendering control based on another thread I found on the internet, these options are -Dsun.java2d.d3d=false and -Dsun.java2d.noddraw=true. Disabling direct draw did not help, I disabled the Direct3D this afternoon and waiting to see if it helps. Has anyone ever seen anything like this before, or have an inkling what might be going on
VIEWS ON THIS POST

94

Posted on:

Sunday 23rd September 2012
View Replies!

Updating JFrame is too slow (Fullscreen)

I'm trying to simulate an LED display for a device. Right now I'm drawing one image to a fullscreen JFrame, updating the image depending on which LEDs should be turned on. Right now it seems to update far too slowly, for example everything turns on at the end of the "Exposure" loop. I had a sample running alright before drawing to a JPanel canvas, but now I'm running into issues when full screen. There are comments spaced through the code showing how the JPanel was set up in this newer version. Any suggestions to get headed in the right direction Also, this is set up fairly poorly in two classes because I'll need a while loop running at one point (single LED blinking on/off until keypress), and I need to set up the KeyListener in another thread I think. _____________ Some sample functions: Start: Ask for "Exposure Time" User will input 6, 7, 8, 9, or 10 "Exposure Time" divided by 4 = sequence time (in seconds) When user pushes the "p" key (power): turn on LED 1 Exposure: When the user push the "s" key (start): Delay .2 seconds Turn on LED 3 Wait "sequence time" Turn on LEDs 4 and 5 Wait "sequence time" Turn on LEDs 6 and 7 Wait "sequence time" Turn on LEDs 8 and 9 Wait "sequence time" Turn on LEDs A and B _____________ public class Simulation extends JFrame implements Runnable { // this line is needed to avoid serialization warnings private static final long serialVersionUID = 1L; private Component frame; private double exposureTime; private int sequenceTime; private boolean alertState; private boolean powerState; private boolean exposing; DisplayCanvas canvas; Image screenImage; // downloaded image int w, h; // Display height and width Thread sim; // Class constructor Simulation() { exposurePrompt(); sim = new Thread(this, "Simulation"); sim.start(); // Exiting program on window close addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_P: Game.power(); break; case KeyEvent.VK_S: try { Game.exposure(); } catch (InterruptedException e1) { e1.printStackTrace(); } break; /* case KeyEvent.VK_F: Game.finish(); break; case KeyEvent.VK_A: Game.alert(); break; */ case KeyEvent.VK_ESCAPE: System.exit(0); break; } } @Override public void keyReleased(KeyEvent arg0) {} @Override public void keyTyped(KeyEvent arg0) {} }); // remove window frame this.setUndecorated(true); // window should be visible this.setVisible(true); // switching to fullscreen mode GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(this); // getting display resolution: width and height w = this.getWidth(); h = this.getHeight(); System.out.println("Display resolution: " + String.valueOf(w) + "x" + String.valueOf(h)); // loading startup image screenImage = Toolkit.getDefaultToolkit().getImage("res/off.jpg"); /* canvas = new DisplayCanvas(); canvas.setPreferredSize(new Dimension(w, h)); Container contentPane = getContentPane(); contentPane.add(canvas); */ } private void exposurePrompt() { powerState = false; exposing = false; Object[] possibilities = {"6", "7", "8", "9", "10"}; String s = (String)JOptionPane.showInputDialog(frame, "Exposure time (seconds):", "LED Simulation", JOptionPane.PLAIN_MESSAGE, null, possibilities, null); exposureTime = Double.parseDouble(s); sequenceTime = (int) Math.ceil((exposureTime / 4) * 1000); } public void run() { // TODO: // Break out of while loop // with KeyListener canvas.paintComponent(this.getGraphics()); } public void setImage(String jpg){ screenImage = Toolkit.getDefaultToolkit().getImage(jpg); SwingUtilities.updateComponentTreeUI(this); // canvas.paintComponent(getGraphics()); } @Override public void paint (Graphics g) { // if (screenImage != null) // if screenImage is not null (image loaded and ready) g.drawImage(screenImage, // draw it 0, 0, w, screenImage.getHeight(this), this); // to draw image at the center of screen // we calculate X position as a half of screen width minus half of image width // Y position as a half of screen height minus half of image height } // ----- POWER GETTERS AND SETTERS ------ public boolean isOn() { return powerState; } public void turnOn() { powerState = true; setImage("res/power.jpg"); } public void turnOff() { powerState = false; setImage("res/off.jpg"); Thread.sleep(750); exposurePrompt(); // TODO: Bring window to front } // // ----- EXPOSING GETTERS AND SETTERS ------ public boolean isExposing() { return exposing; } public void setExposing(boolean b) { exposing = b; } public int getSequenceTime(){ return sequenceTime; } // DISPLAY CANVAS CLASS // ------------------- class DisplayCanvas extends JPanel { private static final long serialVersionUID = 1L; @Override public void paintComponent(Graphics g) { g.drawImage(screenImage, 0, 0, w, screenImage.getHeight(this), this); super.paint(g); } } }
VIEWS ON THIS POST

62

Posted on:

Monday 24th September 2012
View Replies!

GUI design advice needed for window displaying an image

I have a tool (class) pretty well completed which allows a user to navigate through a possibly long list of our unique image files and choose one to display in a separate window. I need the user to be able to sequentially choose more than one so that they may be compared. I don't really want to keep track of multiple windows in the tool. The class is named, for now, ImageWindow.java. I expect the displayed image window to have a status bar and a JPanel just below the title bar to display a line of image statistics. I want a popup menu (mouse right click on the image) and the ability to get the mouse position over the image so that I may display the raw data value. We will have three or 4 sizes of images with the smaller ones needing to be zoomed in and the larger zoomed out. I'm still leaning Java and am especially new to GUI code. I'm not sure exactly how to proceed at this point. I'll have data that cannot be static, I think. Should the ImageWindow extend JPanel, implement MouseMotionListener, and have a main This would be similar to the example I found. Should I use a different structure
VIEWS ON THIS POST

135

Posted on:

Monday 24th September 2012
View Replies!

Single window to open document formats

I've created separate classes for opening document formats like rtf, pdf, html and txt. But all these open in separate windows as they call different classes. I actually want to make a single file chooser which can open all these documents in a single window depending upon the file extension. Please suggest the method.
VIEWS ON THIS POST

61

Posted on:

Tuesday 25th September 2012
View Replies!

Trying to get a square change color on button click

EDIT: Obviously a beginners question! Probably in the wrong forum, please feel free to move mods! Apologies! I thought I'd help myself understanding the GUI and ActionListener proces a bit better by sussing out how to do something simple like putting a button and a rectangle on a screen and then having it change color from blue to red on buttonclick. Appears I've ended up in a swamp and everytime I move I get sucked farther in. I soon found out I have no clue how to easily change the color of something when clicking a button so I thought I'd fake it first by simply running a different color panel on mouseclick. And that failed miserably too! Trying to use the boolean swoosh in two different classes is not the way to go. So a little help, hint or push in the right direction would be greatly appreciated! import javax.swing.*; import java.awt.*; import java.awt.event.*; public class KnopOefen implements ActionListener { JFrame frame; public static void main(String[] args) { boolean swoosh = true; KnopOefen knop = new KnopOefen(); knop.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Click to make the square red!"); button.addActionListener(this); Rectangle recty = new Rectangle(); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.getContentPane().add(BorderLayout.CENTER, recty); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { boolean swoosh = false; KnopOefen knip = new KnopOefen(); knip.go(); } }
VIEWS ON THIS POST

148

Posted on:

Wednesday 26th September 2012
View Replies!

adding background image to JSPlitPane

How can i set background image to the lef side of the JSplitPane.
VIEWS ON THIS POST

109

Posted on:

Wednesday 26th September 2012
View Replies!