Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JColorChooser question (newbie!!!)

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
the code below compiles with the error

Painter.java:60: not an enclosing class:ShowColors2 JColorChooser.showDialog( ShowColors2.this,

but i am not sure why can any give me some good hints plz

here is the code below

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Painter extends JFrame
{
private int xValue = -10, yValue = -10;
private JButton changeColor;
private Color color = Color.lightGray;
private Container c;



public Painter()
{
super( "A simple paint program" );

//c = getContentPane();
//c.setLayout( new FlowLayout() );
//changeColor = new JButton( "Change Color" );
//c.add( changeColor );

getContentPane().add(
new Label( "Drag the mouse to draw" ),
BorderLayout.SOUTH );

addMouseMotionListener(
new MouseMotionAdapter() {
public void mouseDragged( MouseEvent e )
{
xValue = e.getX();
yValue = e.getY();
repaint();
}
}
);

setSize( 800, 600 );
show();
}




public void ShowColors2()
{
//super( "Using JColorChooser" );

c = getContentPane();
c.setLayout( new FlowLayout() );

changeColor = new JButton( "Change Color" );
changeColor.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
color =
JColorChooser.showDialog( ShowColors2.this,
"Choose a color", color );

if ( color == null )
color = Color.lightGray;

c.setBackground( color );
c.repaint();
}
}
);
c.add( changeColor );

setSize( 800, 600 );
show();
}





public void paint( Graphics g )
{
g.fillOval( xValue, yValue, 4, 4 );
}

public static void main( String args[] )
{
Painter app = new Painter();

app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}

}

 
I think you probaly want to change this line :

color = JColorChooser.showDialog( ShowColors2.this, "Choose a color", color );

to :

color = JColorChooser.showDialog(this, "Choose a color", color );

If this does not work, ask your question in forum269 because this forum isn't used much anymore ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top