Wednesday, November 5, 2014

Awt Button java pro



Change AWT Button Font

import java.applet.Applet;
import java.awt.Button;
import java.awt.Font;
public class ChangeButtonFontExample extends Applet
{
public void init()
{
Button button1 = new Button("Button 1");
Button button2 = new Button("Button 2");
Font myFont = new Font("Courier", Font.Italic,12);
button1.setFont(myFont);
add(button1);
add(button2);
   }
}

Change Button Background Color

import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
public class ChangeButtonBackgroundExample extends Applet
{   
public void init()
{
Button button1 = new Button("Button 1");
Button button2 = new Button("Button 2");
button1.setBackground(Color.red);
button2.setBackground(Color.green);
add(button1);
add(button2);
    }
}

Change Button Foreground Color

import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
public class ChangeButtonForegroundExample extends Applet
{
public void init()
{
Button button1 = new Button("Button 1");
Button button2 = new Button("Button 2");
button1.setForeground(Color.magenta);
button2.setForeground(Color.blue);
add(button1);
add(button2);
   }
}

Create AWT Button

import java.applet.Applet;
import java.awt.Button;
public class CreateAWTButtonExample extends Applet
{
public void init()
{
Button button1 = new Button();
button1.setLabel("My Button 1");
Button button2 = new Button("My Button 2");
add(button1);
add(button2);
   }
}

Determine If The Button Is Enabled

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Button; 
public class DetermineIfButtonEnabled extends Applet
{       
boolean isButton1Enabled;
boolean isButton2Enabled;   
public void init()
{
Button Button1 = new Button("Ok");
Button Button2 = new Button("Cancel");
add(Button1);
add(Button2);               
Button1.setEnabled(false);
isButton1Enabled = Button1.isEnabled();
isButton2Enabled = Button2.isEnabled();             
}      
public void paint(Graphics g)
{
g.drawString("Is Button 1 enabled? " + isButton1Enabled, 10,50);
g.drawString("Is Button 2 enabled? " + isButton2Enabled, 10,70);
  
}

Determine If the Button Is Visible

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Button;
public class DetermineIfButtonVisible extends Applet
{
boolean isButton1Visible;
boolean isButton2Visible;
public void init()
{
Button Button1 = new Button("Ok");
Button Button2 = new Button("Cancel");
add(Button1);
add(Button2);             
Button2.setVisible(false);
isButton1Visible = Button1.isVisible();
isButton2Visible = Button2.isVisible();           
}
public void paint(Graphics g){
g.drawString("Is Button 1 visible? " + isButton1Visible, 10,50);
g.drawString("Is Button 2 visible? " + isButton2Visible, 10,70);
   }
}

No comments:

Post a Comment