aspose file tools*
The moose likes Beginning Java and the fly likes Hello Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hello" Watch "Hello" New topic
Author

Hello

Jose Carrillo
Greenhorn

Joined: Nov 13, 2003
Posts: 17
hi I'm having a problem and I do not find what is problem well. I creating an applet with 4 buttons draw lines, rect, ovals, and fill. when fill button is click it will draw the rect and ovals fill. well my program compile and everything but I does not load the applet in the web can somebody help please. here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.EventObject;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[4];
private JPanel controlPanel, drawPanel;
private int shape;
private Button fillButton;
private Panel currentcolorPanel;
public static boolean FillShape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[3] = new JButton("Fill");
buttons[0].setBackground(Color.red);
currentcolorPanel.add(fillButton);
fillButton.addActionListener(this);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<4; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<4; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
int [] a = new int [x];
int [] z = new int [y];
break;
case 1: g.drawRect(x, y, w, h);
int [] b = new int [x];
break;
case 2: g.drawOval(x, y, w, h);
int [] c = new int [x];
break;
case 3: g.fillRect(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getSource() == fillButton)
{
if(FillShape)
{
FillShape = false;
fillButton.setLabel("Unfilled");
return;
}
FillShape = true;
fillButton.setLabel("Filled");
}
for (int i=0; i<4; i++)
{
buttons[i].setBackground(Color.lightGray);
if (actionevent.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
thanks
Jasmine kaur
Ranch Hand

Joined: Nov 25, 2003
Posts: 157
Hello ,
Well you want to run applet then you should use appletviewer whivh is present in the bin folder but before that you have to put the applet code tag in your source code only then it would run sucessfully on the web.
so put this cod ein your source code
as **/<applet code="myapllet.class"Height=200width=200>
</applet> **/
you have to put the same synatx in your source code and then compile your code then you can run your applet like this
appletviewer myapplet.java so you can easily see your applet then you can put this in html file by putting the applet code tag and run the html file on browser .
So do this you code will run .If you face some confusion you can ask more.
Thanks
Jasmine kaur


jasmine kaur
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hello
 
Similar Threads
Please Help?
Help 3
HELP
HELP 5
HELP2