Skip to main content

Display Text in Blue and Green Colours - Netbeans Java Codes


You can also download text file of this code here:  Blue-Greentexts.txt

Java Codes:

public class ActionExample extends Applet implements ActionListener
{
    AudioClip audio;

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

     public void init() 
     {
  // Now we will use the FlowLayout[Find More Java Codes at www.sumikuma.tk]
          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);

  // Attach actions to the components
          okButton.addActionListener(this);
          wrongButton.addActionListener(this);
         }

 // Here we will show the results of our actions[Find More Java Codes at www.sumikuma.tk]
         public void paint(Graphics g)
         {
  // If the radio1 box is selected then radio1.getState() will
  // return true and this will execute
          if (radio1.getState()) g.setColor(Color.red);
  // If it was not red we'll try if it is blue
        else if (radio2.getState()) g.setColor(Color.blue);
  // Since always one radiobutton must be selected it must be green
          else g.setColor(Color.green);

  // Now that the color is set you can get the text out the TextField
  // like this
          g.drawString(nameField.getText(),20,100);
     }

 // When the button is clicked this method will get automatically called
 // This is where you specify all actions.

        public void actionPerformed(ActionEvent evt) 
         {
  // Here we will ask what component called this method
              if (evt.getSource() == okButton) {
                  audio = getAudioClip(getCodeBase(),"TestSnd.wav");
        audio.stop();
        audio.play();
              
                  
   // So it was the okButton, then let's perform his actions
   // Let the applet perform Paint again.
   // That will cause the aplet to get the text out of the textField
   // again and show it.
                   repaint();
              }
  // Actions of the wrongButton
          else if (evt.getSource() == wrongButton) 
          {

   // Change the text on the button for fun[Find More Java Codes at www.sumikuma.tk]
               wrongButton.setLabel("Not here!");
   // Changes the text in the TextField
               nameField.setText("That was the wrong button!");
   // Lets the applet show that message.
               repaint();
          }
     } 

}

Comments

Popular posts from this blog

Binary Converter - Netbeans Java Codes

You can also download text file of this code here:   BinaryConverter.txt Java Code: public class BinaryConv { public static void main(String[] args) { Scanner in = new Scanner(System.in); int decimalNumber; String binaryNumber; System.out.print("Enter a positive integer: "); decimalNumber = in.nextInt(); if (decimalNumber <= 0) System.out.println("ERROR: entered integer is nonpositive."); else { binaryNumber = ""; // algorithm step by step // initial: binaryNumber = "", decimalNumber = 123 // step 1 : binaryNumber = "1 ", decimalNumber = 61 // step 2 : binaryNumber = "11 ", decimalNumber = 30 // step 3 : binaryNumber = "011 ", decimalNumber = 15 // step 4 : binaryNumber = "1011 ", decimalNumber = 7 // step 5 : binaryNumber = "1 1011 ", decimalNumber = 3 // step 6 : binaryNumber = "11 1011 ", decimalNumber = 1 // step 6 : binaryNumber = "111 1011 ",...

Javax Code for Playing Music:

Javax Code for Playing Music: OUTPUT: ________________________________________________________________ Just Copy and Paste and Change the variable name respectively: ________________________________________________________________ ________________________________________________________________ Buttons: 1. jButton1 : Open Music File 2. jButton2 : Play 3, jButton3 : Stop 4. jButton4 : Pause ________________________________________________________________ import java.io.File;     import java.io.IOException;     import java.net. MalformedURLException;     import javax.sound.sampled. AudioInputStream;     import javax.sound.sampled. AudioSystem;     import javax.sound.sampled.Clip;     import javax.sound.sampled. LineUnavailableException;     import javax.sound.sampled. UnsupportedAudioFileException; public class Music extends javax.swing.JFrame {     /** ...

Get Current System Time & Date - Netbeans Java Code

Run Shot of Current System Time & Date Java Code: import java.text.SimpleDateFormat; import java.util.Date; public class Datetimemonth { public static void main(String[] args) { Date now = new Date(); System.out.println("toString(): " + now); // dow mon dd hh:mm:ss zzz yyyy // SimpleDateFormat can be used to control the date/time display format: // E (day of week): 3E or fewer (in text xxx), >3E (in full text) // M (month): M (in number), MM (in number with leading zero) // 3M: (in text xxx), >3M: (in full text full) // h (hour): h, hh (with leading zero) // m (minute) // s (second) // a (AM/PM) // H (hour in 0 to 23) // z (time zone) SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z"); System.out.println("Format 1: " + dateFormatter.format(now)); dateFormatter = new Sim...