Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Abdullah Al- Mamun
Applet
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners


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

public class Triangle extends JApplet
implements MouseListener {

// The rest of the applet will be in the next
// example.
Point[] pt = new Point[3];
int ptCount = 0;

public void paint(Graphics g) {

int i;

// Draw the points that have been selected

for (i = 0; i < ptCount; i++) {
g.fillOval(pt[i].x - 10, pt[i].y - 10,
20, 20);
}

if (ptCount == 3) {

// Connect the endpoints to handle
// tall thin triangles.

g.drawLine(pt[0].x, pt[0].y,
pt[1].x, pt[1].y);
g.drawLine(pt[1].x, pt[1].y,
pt[2].x, pt[2].y);
g.drawLine(pt[0].x, pt[0].y,
pt[2].x, pt[2].y);

// Calculate x and y diffs between points.

int x0to1 = pt[1].x - pt[0].x;
int x0to2 = pt[2].x - pt[0].x;
int x1to2 = pt[2].x - pt[1].x;
int y0to1 = pt[1].y - pt[0].y;
int y0to2 = pt[2].y - pt[0].y;
int y1to2 = pt[2].y - pt[1].y;

// Left part of the triangle.

if (x0to1 > 0) {
for (i = pt[0].x; i <= pt[1].x; i++) {
g.drawLine(
i,
pt[0].y +
((y0to1 * (i - pt[0].x)) / x0to1),
i,
pt[0].y + ((y0to2 * (i - pt[0].x)) / x0to2)
);
}
}

// Right part of the triangle.

for (i = pt[1].x+1; i <= pt[2].x; i++) {
g.drawLine(
i,
pt[1].y +
((y1to2 * (i - pt[1].x)) / x1to2),
i,
pt[1].y +
((y0to2 * (i - pt[0].x)) / x0to2)
);
}
}
}
}

Advertisement
View Answers

May 5, 2010 at 1:18 PM


Hi Friend,

Please specify the error so that we can help you.

Thanks


Related Tutorials/Questions & Answers:
Applet
Applet  Write an applet to display a string in an applet. String should be passed as a parameter to an applet
Applet
Applet  Give the class hierarchy of an Applet class
Advertisements
applet
applet  Explain different stages in the lifecycle of an applet with figure.   Stages of Applet: Life cycle of an Applet: init(): This method is called to initialized an applet start(): This method is called after
Applet
Applet  how to run an applet on a web browser
applet
applet  What is the immediate superclass of the Applet class
Applet
Applet  Write a ava applet that sets blue color foreground and yellow color background at the start of an applet
Applet
Applet  Explain the start() and stop() methods of applet life cycle.   Start and Start method of Applet Life Cycle Start () method: The start method of an applet is called after the initialization method init
Applet
Applet  I have a java applet that has a button. On clicking the button it should disappear and another applet should appear. How to write this code???? Also in login applet after successful login it should display admin applet
Applet
Applet  Write a short note on applet life cycle
Applet
Applet  Draw the class hierarchy of an Applet class. Also explain how to set background and forground colors in java
applet
applet  what is applet in java   An applet is a small program that can be sent along with a Web page to a user. Java applets can perform... the following link: Applet Tutorials
Applet
Applet  Write a Java applet that drwas a line between 2 points. The co-ordinates of 2 points should be passed as parametrs from html file. The color of the line should be red
applet
applet  applet to open new tab not working.here's my code import java.applet.*; import java.awt.*; import java.net.*; import java.awt.event.*; public class NewURL extends Applet implements ActionListener{ public void init
applet - Applet
.  Hi Friend, Try the following code: 1)Create an applet... extends Applet{ public void paint(Graphics g){ g.drawString("Welcome in Java Applet.",40,20); } } 2) Call this applet with html code
Applet - Applet
Applet  what is the concept of applet? what is different between the applet concept and HTML? what is mean by swing?  Hi friend, Applet Applet is java program that can be embedded into HTML pages. Java applets
applet - Applet
*; import java.awt.*; public class CreateTextBox extends Applet implements.../applet/ Thanks
Applet - Applet
Applet   Namaste, I want to create a Menu, the menu name is "Display... java.awt.event.*; public class menu2frame extends Applet implements WindowListener...------------------------"); g.drawString("Demo of Java Applet Window Event Program"); g.drawString("Java
applet problem - Applet
applet problem  How can I create a file in client side by a java applet . Surely it will need a signed applet .But how can a signed applet create a file in the client side
embedding class in an applet - Applet
embedding class in an applet  I have an applet that has a set... java.awt.event.*; public class tesURL extends Applet implements ActionListener... a remote controller). I have the applet code for the remote controller
Applet codebase
Applet codebase  What is codebase in applet
Servlet and Applet - Applet
Invoke and run an Applet from Servlet  How can i invoke and run an applet from servlet. Can anyone provide me the sample code
java - Applet
java  what is applet
creating hyperlinks in applet - Applet
creating hyperlinks in applet  Dear sir, how can i move from one applet to another applet and how can i use previous applet input data in anotherapplet(just like session tracking) thanks
Applet JSP communication - Applet
Applet JSP communication  Hi.. I've an application where i need to get the data from the applet to JSP... How can i do this..?? can anyone explain with a sample code
applet program code - Applet
applet program code  hello sir, i did't get the code for below problem... please help me... 1.An applet program to draw a line graph for y=2x+5.[for suitable values of x & y
applet running but no display - Applet
applet running but no display  Hai, Thanks for the post. I have... from a client, the page appears with a blank applet part (just whitescreen..., it is showing that the "Applet as1 started". Please help me to solve this issue
What is Applet? - Applet
What is Applet?  What is Applet?  Hi,Here is a little information about Applet.An applet is a little application. Prior to the World Wide... programming language, an applet is a small program that can be sent along with a Web
applet Question
applet Question  Write a java applet to display a circle in a rectangle
applet question
applet question  Write a java applet to display a rectangle inside a circle
applet question
applet question  Write a java applet to display atriangle inside a circle
java applet - Applet
java applet  wants to creat address bar on my java applet.  Hi Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
 

 

 

DMCA.com