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

MATCH REPORT: BNI INDONESIA ALL-STARS 1 CHELSEA 8

MATCH REPORT: BNI INDONESIA ALL-STARS 1 CHELSEA 8 Summary  An enormous and vociferous crowd of Chelsea fans came to see the team on our Indonesian debut and they were rewarded with goals galore, including some quality strikes, as the Asia tour ended in style. The Chelsea goals were split equally between the halves - Eden Hazard, Ramires, Demba Ba and John Terry the scorers before half-time, with Ramires again finding the net after the interval and Romelu Lukaku scoring two as well. Bertrand Traore added to his goal in Malaysia shortly after coming on at half-time. The sole goal from the Indonesian All-Stars was an own-goal, conceded when we were already 8-0 up. Gary Cahillwas the one Chelsea man to play 90 minutes. Chelsea  (4-3-3): Blackman (Schwarzer h-t); Wallace (Ivanovic h-t), Cahill, Terry (c) (Kalas h-t), Bertrand (Cole h-t);Ramires (Feruz 59), Chalobah (Essien h-t), Van Ginkel (McEachran 59); Moses (Traore h-t), Ba (Lukaku h-t), Hazard (Piazon 59). Scorers

ARJUN COOM's Kabhi-Kabhi [feat. Shivali & Natasha] Song Lyrics

MUSIC Written, produced and performed by Arjun Hindi chorus performed by Shivali and Natasha Originally written by Khayyam  Mixing - Elliot Bradley, Soho Studios ------------------------------------------------------------------------------------- Chorus: Kabhi Kabhi Mere Dil Mein Khayal ata Hai Kabhi Kabhi Mere Dil Mein Khayal Ata Hai I feel like a plane on a runaway about to lift off I feel like an ocean so deep, deep as my love You should know that it's you that I've chosen and I'm ready to give you my all Yes I'm right open Come and get, come and get it. You know that I could be. The one that makes you complete 'Cause I've fallen head over heels, and you're the only one. Chorus: Kabhi Kabhi Mere Dil Mein Khayal Aata Hai Kabhi Kabhi Mere Dil Mein Khayal Aata Hai Kii Jaise Tujhko Banaya Gyaa Hai Mere Liye Kii Jaise Tujhko Banaya Gyaa Hai Mere Liye I used to be lost in the darkness, but you were my star. I feel like a king when I'm in your arms, and

Calculator - Netbeans Java Code

Run Shot of Calculator Java Code: public class Calculator { public static void main(String[] args) { boolean go = true; //sets up loop while(go) //creates loop to top { System.out.println("Hello this is my calculator!"); System.out.println("To add, type a, to subtract, type s."); System.out.println("To multiply, type m, to divide, type d."); Scanner scan = new Scanner(System.in); //sets up scanners Scanner scan1 = new Scanner(System.in); String action = scan.nextLine(); //tells comp. to take user input if("a".equals(action)) //addition { System.out.println("Now type in the first number you would like to add."); int add1 = scan.nextInt(); System.out.println("Now type the second number."); int add2 = scan.nextInt();