How to write a simple java applet

Ads

 
 

Share on Google+Share on Google+

michael wong
How to write a simple java applet
2 Answer(s)      6 years and 11 months ago
Posted in : Java Beginners

Hi, how can i write a simple java applet, displaying text in specific colors and font style.

For example, the output will be something like : Name in red color Age in blue color Nationality in green color

Help me pls :(

Ads
View Answers

November 25, 2010 at 12:23 PM


Hi Friend,

Try the following code:

import java.awt.*;
import java.applet.*;

public class ShowsTextExample extends Applet{
 public void paint(Graphics g){
      g.setColor(Color.black); 
      g.drawString("Name:",10,10);
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  

      g.setColor(Color.red); 
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  
      g.drawString("Rose",100,10);

      g.setColor(Color.black); 
      g.drawString("Age:",10,40);
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  

      g.setColor(Color.blue); 
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  
      g.drawString("20",100,40);

      g.setColor(Color.black); 
      g.drawString("Nationality:",10,70);
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  

      g.setColor(Color.green); 
      g.setFont(new Font("Monotype Corsiva",Font.BOLD,20));  
      g.drawString("20",100,70);
 }
}

Thanks



November 30, 2010 at 1:33 PM


thank you for the code...its really work :)


Ads









Related Tutorials/Questions & Answers:
How to write a simple java applet
How to write a simple java applet   Hi, how can i write a simple java applet, displaying text in specific colors and font style. For example... Applet{ public void paint(Graphics g){ g.setColor(Color.black
Simple java applet
Simple java applet  Create a Java applet to display your address on the screen. Use different colors for background and text   Please visit the following link: Applet Examples
Advertisements
Write a Java applet to draw cylinder and pentagon shapes.
Write a Java applet to draw cylinder and pentagon shapes.  Write a Java applet to draw cylinder and pentagon shapes
Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application that require user to login by username and password. After login, they should meet
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How to write in File of Java Program
How to Write to file in Java?
How to Write to file in Java?  How to Write to file in Java Program... the Examples of How to write to File in Java Program: WriteToFileExample.java import... how to write in a file."); br.close(); } catch (Exception e) { System.err.println
Applet Write Files Example
Applet Write Files Example       In this section, you will learn how to write to a file from an applet. This is very simple but the security manager don't provide
Help me to write this simple java frame program
Help me to write this simple java frame program   I want to write a Java program for.... To create a frame with 4 text fields;name,street,city and pin;with suitable labels. Also add a button "OK". After enter values
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file in Java   Hi, To create Comma separated value(CSV) file is very simple... Object to PrintWriter instance. How to create File to CSV in Java
write simple java code - Java Beginners
write simple java code  Write a program that creates a simple calculator .The user enters two numbers in the text fields, Number 1 and Number 2. There are 4 buttons, labeled with ?Add?, ?Substract?, ?Multiply? and ?Divide
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java with the help of a sample Java program. After going though this tutorial you... to a file from Java program. To write the Java Write To File we will use two
how to write java data - XML
how to write java data  how to write data to xml file  Hi friend, Read for more information, http://www.roseindia.net/xml/dom/ Thanks
How to Write To File BufferedWriter in Java
How to Write To File BufferedWriter in Java  how to write to file bufferedwriter in Java   In Java there are 2 types of class files used... for your references. How to use Bufferedwriter class in Java programs
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
how to write append file in Java
how to write append file in Java  How to write append file in Java... existing file should be retained when you are trying to write new contents in an existing files. For this in java program we uses WriteToFileAppend.java to be used
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
how to run applet - Applet
://www.roseindia.net/java/example/java/applet/ http://www.roseindia.net/java/example/java/applet/FirstApplet.shtml Hope that it will be helpful for you.Even...how to run applet   Hi everybody i am using connecting jdbc
Java Applet
Java Applet   How to add Image in Java Applet? what is getDocumentBase
how to write this program? - Java Beginners
how to write this program?  (game:scissor,rock ,paper) A program that plays the sciccor-rock-paper game.Revise the program to let the user continuously play until either the user or the computer wins more than 4 times
how to write the program - Java Beginners
how to write the program  WAP to create the report card user input Name, Class, Division, Roll no., Marks obtained in following subjects Lang Hindi History Geography Math Phy Chem. Bio Eve CSTA Also has a back up
java - Applet
java  how to connect database table with scrollbar in java applet
java - Applet
java  how to connect database table with scrollbar in java applet
Q6 Write a java applet that displays 9 squares, one below the other. Every third square must be filled in black?
Q6 Write a java applet that displays 9 squares, one below the other. Every third square must be filled in black?  Q6 Write a java applet that displays 9 squares, one below the other. Every third square must be filled in black
Write an applet that prints "Lear Java it is useful" at the current cursor position whenever the mouse left button is clicked.
Write an applet that prints "Lear Java it is useful" at the current cursor position whenever the mouse left button is clicked.   Write an applet that prints "Lear Java it is useful" at the current cursor position whenever
How to write in Binary file in Java programming language
How to write in Binary file in Java programming language  I need some help about Java programming. Please explain me "How to write in Binary file in Java programming language
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java programming. Thanks,   Hi, Are you eager to learn how to write to file from
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Write an applet to display scrolling image in an applet window using thread.
Write an applet to display scrolling image in an applet window using thread.  Write an applet to display scrolling image in an applet window using thread