Showing posts with label applets. Show all posts
Showing posts with label applets. Show all posts

Monday, 5 August 2013

Java Applet: ActionListener in java applets

// siddhu vydyabhushana // Leave a Comment
 ActionListener in java applets
Program:
 import java.awt.*; 
import java.applet.*; 
import java.awt.event.*; 

/*<applet code="ActionExample.java" width=300 height=500>
</applet>
*/

public class ActionExample extends Applet implements ActionListener 
{ 

     Button okButton; 
     Button wrongButton; 
     TextField nameField; 
     CheckboxGroup radioGroup; 
     Checkbox radio1; 
     Checkbox radio2; 
     Checkbox radio3; 

     public void init()  
     { 
          setLayout(new FlowLayout()); 
          okButton = new Button("Action!"); 
          wrongButton = new Button("Don't click!"); 
          nameField = new TextField("Type here Something",35); 
          radioGroup = new CheckboxGroup(); 
          radio1 = new Checkbox("Red", radioGroup,false); 
          radio2 = new Checkbox("Blue", radioGroup,true); 
          radio3 = new Checkbox("Green", radioGroup,false); 
          add(okButton); 
          add(wrongButton); 
          add(nameField); 
          add(radio1); 
          add(radio2); 
          add(radio3); 
          okButton.addActionListener(this); 
          wrongButton.addActionListener(this); 
         } 
         public void paint(Graphics g) 
         { 
          if (radio1.getState()) g.setColor(Color.red); 
        else if (radio2.getState()) g.setColor(Color.blue); 
          else g.setColor(Color.green); 

          g.drawString(nameField.getText(),20,100); 
     } 

 
        public void actionPerformed(ActionEvent evt)  
         { 
              if (evt.getSource() == okButton)  
                   repaint(); 

          else if (evt.getSource() == wrongButton)  
          { 

               wrongButton.setLabel("Not here!"); 
               nameField.setText("That was the wrong button!"); 
               repaint(); 
          } 
     }  

} 
Output:

Read More

Saturday, 3 August 2013

Java Applets: How to change the color of text in applets dynamically

// siddhu vydyabhushana // 5 comments
How to change the color of text in applets dynamically


How to change the color of text in applets dynamically:
 
import java.awt.*;        // Defines basic classes for GUI programming.
     import java.awt.event.*;  // Defines classes for working with events.
     import java.applet.*;     // Defines the applet class.
 


/*<applet code="ColoredHelloWorldApplet" width=300 height=400>
</applet>
*/
     public class ColoredHelloWorldApplet
                       extends Applet implements ActionListener {
 
           // Defines a subclass of Applet.  The "implements ActionListener"
           // part says that objects of type ColoredHelloApplet are
           // capable of listening for ActionEvents.  This is necessary
           // if the applet is to respond to events from the button.
 
        Font textFont;    // The font in which the message is displayed.
                          // A font object represent a certain size and
                          // style of text drawn on the screen.
        TextField T1;
        TextField T2;
        TextField T3;
        int redColor, greenColor, blueColor;
        String as, ag, ab;
        Button bttn;
        public void init() {
 
               // This routine is called by the system to initialize 
               // the applet.  It sets up the font and initial colors
               // the applet.  It adds a button to the applet for 
               // changing the message color.
 
            setBackground(Color.lightGray);
                  // The applet is filled with the background color before
                  // the paint method is called.  The button and the message
                  // in this applet will appear on a light gray background.
 
            redColor=0;
            greenColor=0;
            blueColor=0;
 
 
            textFont = new Font("Serif",Font.BOLD,24);
                  // Create a font object representing a big, bold font.
 
     /*
     		TextField T1=new TextField("",12);
     		TextField T2=new TextField("",12);
     		TextField T3=new TextField("",12);
     		*/
 
     		T1=new TextField("",12);
     	 	T2=new TextField("",12);
     	 	T3=new TextField("",12);
 
 
     		add(T1);
     		add(T2);
     		add(T3);
            bttn = new Button("Change Color");
                  // Create a new button.  "ChangeColor" is the text
                  // displayed on the button.
 
            bttn.addActionListener(this);  
                  // Set up bttn to send an "action event" to this applet
                  // when the user clicks the button.  The parameter, this,
                  // is a name for the applet object that we are creating.
 
            add(bttn);  // Add the button to the applet, so that it 
                        // will appear on the screen.
 
        }  // end init()
 
 
        public void paint(Graphics g) {
 
              // This routine is called by the system whenever the content
              // of the applet needs to be drawn or redrawn.  It displays 
              // the message "Hello World" in the proper color and font.
 
           Color mixColor=new Color(redColor, greenColor,blueColor);
           //Color mixColor=new Color(255,255,50);
 
           //g.setColor(mixColor);
           g.setColor(mixColor);
           //g.setColor(new Color(redColor, greenColor, blueColor));
           g.setFont(textFont);       // Set the font.
 
           g.drawString("This Color changes", 20,70);    // Draw the message.
           //T1.setText("Is this function reached");
 
        }  // end paint()
 
 
        public void actionPerformed(ActionEvent evt) {
 
              // This routine is called by the system when the user clicks
              // on the button.  The response is to change the colorNum
              // which determines the color of the message, and to call
              // repaint() to see that the applet is redrawn with the
              // new color.
            // T1.setText("23");
 
            if (evt.getSource() == bttn)
            {
 
              as=T1.getText();
              ag=T2.getText();
              ab=T3.getText();
       	  	  as=as.trim();
          	  ag=ag.trim();
              ab=ab.trim();
 
           redColor= Integer.parseInt(as);
           greenColor= Integer.parseInt(ag);
           blueColor= Integer.parseInt(ab);
 
           repaint();  // Tell system that this applet needs to be redrawn
          }
        }  // end init()
 
     } // end class ColoredHelloWorldApplet

Output:

Read More

Java Applets :How to change button background in applets

// siddhu vydyabhushana // 3 comments
How to change button background in applets

change button background in applets:
/*
        Change Button Background Color Example
        This java example shows how to change button background color using
        AWT Button class.
*/
 
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
 
 
/*
<applet code="ChangeButtonBackgroundExample" width=200 height=200>
</applet>
*/
public class ChangeButtonBackgroundExample extends Applet{
 
        public void init(){
               
                //create buttons
                Button button1 = new Button("Button 1");
                Button button2 = new Button("Button 2");
               
                /*
                 * To change background color of a button use
                 * setBackground(Color c) method.
                 */
               
                button1.setBackground(Color.red);
                button2.setBackground(Color.green);
               
                //add buttons
                add(button1);
                add(button2);
        }
}
Output:

Read More

Monday, 29 July 2013

Difference between applets and application in java

// siddhu vydyabhushana // Leave a Comment

Difference between applets and application

                            Applet                                                                 Application
         1.      Applets  are inherently use the GUI       1.GUI is optional ,mostly character
          E.g: Webpage animation                             based. E.g: Network Sever

   2. Method expected by the JVM is init()     2.JVM expected main() method for                   Start(),stop(),destroy() and paint()             Start up.
        method.   

   3 .It requires more memory and web           3. Less memory required.
        Browser.

    4 .Environmental input are supplied           4.Mostly command line arguments
        Through PARAMETER embedded in 
        host html.
.
Read More

Friday, 26 July 2013

Introduction to Applets

// siddhu vydyabhushana // 2 comments
Introduction to Applets

v  An applet is a special program that you can embed in a web page such that the applet gains control over a certain part of the displayed page.

v  Applet differs from application programs. Like applications, applets are created from classes.

v  However, applets do not have a main method as an entry point, but instead have several methods to control specific aspects of applet execution

simple hello world applet
Compiling JAVA Applet


This applet consists of two import statements.

               1.      The first import the abstract windowing tool kit class. Because applet programs are GUI based not console based.
               2.      The second import statement here is Applet class. Every applet that you can create must be a sub class of Applet.
        3.    The paint method is called to display the output. It has one parameter of type Graphics.
                                
                                   Syntax: drawString(String s1, int x, int y);


Read More

Saturday, 1 December 2012

Insert Data into Database using Swings,Applets part-3

// siddhu vydyabhushana // 3 comments
this part-3 is followed by before 2 parts links are

PART-1

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using.html

PART-2

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using_1.html




DOWNLOAD FULL CODING
                                   download

DATABASE

DB




DATABASE CONNECTION WITHOUT DSN

try
{
String database="sample.mdb";//Here database exists in the current directory

//this connection is without DSN
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=true";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
PreparedStatement st=con.prepareStatement("insert into reg(username,password,gender,email) values(?,?,?,?)");
st.setString(1,name);
st.setString(2,pass);
st.setString(3,g);
st.setString(4,email);
st.executeUpdate();
JOptionPane.showMessageDialog(null,"Data is successfully inserted into database.");
}
catch( Exception ex){}
}
Read More

Insert Data into Database using Swings,Applets part-2

// siddhu vydyabhushana // 9 comments
Good evening guys just now i described all functions of java in part 1 .In part-2  am going to give u front end code and explaination..
follow below steps

 PART-1

http://javatyro.blogspot.in/2012/12/insert-data-into-database-using.html


SCREEN SHOT OF MY PROJECT



DOWNLOAD FULL CODING
                                   download



PACKAGES


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

JText Field component in swings used for input fileds

JTextField jt1=new JTextField(20);
JTextField jt2=new JTextField(20);
JTextField jt3=new JTextField(20);
JTextField jt4=new JTextField(20);

JLabel

JLabel jlb1=new JLabel("Username:");
JLabel jlb1=new JLabel("password:");
JLabel jlb1=new JLabel("confirm password:");
JLabel jlb1=new JLabel("email:");

JRadioButton



JRadioButton m, f;
ButtonGroup radio=new ButtonGroup();

 m=new JRadioButton("male");
radio.add(m);//adding item into JFrame

f=new JRadioButton("female");
radio.add(f);//adding item into JFrame

JButton


JButton button=new JButton("Submit");

Adjust  OBJECTS positions in JFrame

name.setBounds(int x,int y,int height,int width);

jlb1.setBounds(40,50,70,30);//adjust label to co-ordinates
jlb2.setBounds(40,90,70,30);//adjust label to co-ordinates
jlb3.setBounds(40,130,70,30);//adjust label to co-ordinates
jlb4.setBounds(40,170,70,30);//adjust label to co-ordinates

jt1.setBounds(130,50,100,30);//adjust JText Field to co-ordinates
jt2.setBounds(130,90,100,30);//adjust JText Field to co-ordinates
jt3.setBounds(130,130,100,30);//adjust JText Field to co-ordinates
jt4.setBounds(130,170,100,30);//adjust JText Field to co-ordinates

m.setBounds(40,210,100,30);//adjust JRadioButton to co-ordinates
f.setBounds(140,210,100,30);//adjust JRadioButton to co-ordinates

button.setBounds(80,250,100,30);//adjust JButton to co-ordinates

ADD OBJECTS TO JFrame

j.add(img1);
j.add(jlb1);
j.add(jt1);
j.add(jlb2);
j.add(jt2);
j.add(jlb3);
j.add(jt3);
j.add(jlb4);
j.add(jt4);
j.add(m);
j.add(f);
j.add(button);
j.add(text);

EVENT HANDLING

button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//data here
}
});

VALIDATIONS

String name=jt1.getText();
String pass=jt2.getText();
String cpass=jt3.getText();
String email=jt4.getText();
String g=text.getText();

if((name.length()<6)||(name.length()>=15))
{
JOptionPane.showMessageDialog(null,"name field lessthan 15 and greaterthan 6 ");
jt1.setText("");
}
else if(!pass.equals(cpass))
{
JOptionPane.showMessageDialog(null,"password didn't matched");
}
else if(email.length()<10)
{
JOptionPane.showMessageDialog(null,"enter your correct id");
}
else if((m.isSelected()==false)&&(f.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");
}
}

HOW TO POP UP DIALOG


JOptionPane.showMessageDialog(null,"Please select radio button");
Read More

Insert Data into Database using Swings,Applets part-1

// siddhu vydyabhushana // 18 comments
Hi guys this is siddhu vydybhushana. Already i have blog (MY BLOG )but this time i concentrated on java so i create another blog and named JAVATYRO ..!!!!

I used  below topics to complete project

1.Swings
2.AWT
3.JDBC
4.Event Handling

Swings
swing is a part of JFC(java foundation classes).It gives smooth interface than AWT but we need to entire program in java.

JFC
java foundation classes are set of GUI(graphical user interface) components which simplifies the development of desktop applications..

AWT
adstract window toolkit used to develop GUI apps in java we can convert this to web applications also.

WHY EVENT HANDLING?
if we observe any change in state of an object we call it as EVENT . for example button pressing,mouse dragging,dialog showing .........etc
These events are provided by java.awt.event package
it will provide many event classes and listeners




now it is time to discuss about JDBC connection
already in my last post i blogged it please refer the below link to know that

                types-of-jdbc-drivers...

in next part i will go through on coding dont miss it ..

PART-2































Read More