NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package uugn;

import java.awt.event.*;
import java.awt.*;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Exercise3 extends JFrame implements ActionListener {
private JButton btn1, btn2;
private JPanel p1,p2;
private TextField txt1, txt2, txt3;
private Label lb1, lb2;


public Exercise3() {
lb1 = new Label("Character");
lb2 = new Label("String");
txt1 = new TextField();
txt2 = new TextField();
txt3 = new TextField();
btn1 = new JButton("Show");
btn2 = new JButton("Clear");
p1 = new JPanel();
p2 = new JPanel();


p1.add(lb1);
p1.add(txt1);
p1.add(btn1);
p1.add(lb2);
p1.add(txt2);
p1.add(btn2);
p2.add(txt3);
this.add(p1);
this.add(p2);



lb1.setBounds(80, 50, 80, 20);
lb2.setBounds(100, 100, 40, 20);
txt1.setBounds(160, 50, 120, 20);
txt2.setBounds(160, 100, 120, 20);
txt3.setBounds(80, 0, 300, 100);
btn1.setBounds(300, 50, 80, 20);
btn2.setBounds(300, 100, 80, 20);
p1.setLayout(null);
p2.setLayout(null);



btn1.addActionListener(this);
btn2.addActionListener(this);

this.setTitle("Exercise");
this.setLayout(new GridLayout(2, 1));
this.setSize(500,400);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
int i, k, sum=0;

if (e.getSource() == btn1) {
String c = txt1.getText();
String s = txt2.getText();
char ch[] = s.toCharArray();

char c1 = c.charAt(0);
for(i=0;i<s.length();i++){
if(ch[i]==c1) {
sum++;
}
}

txt3.setText(c + " = " + sum + " times " + "Lenght of string " + s.length());

}

if (e.getSource() == btn2) {
txt1.setText("");
txt2.setText("");
txt3.setText("");

}
}

}




package uugn;

import java.awt.event.*;
import java.awt.*;


import javax.swing.*;
import javax.swing.plaf.ColorUIResource;




public class Exercise2 extends JFrame implements ActionListener {
private JButton b1 ;

private JPanel p1;

public Exercise2() {


p1 = new JPanel();
b1 = new JButton("→");


p1.setSize(120,100);
p1.setLocation(170,50);
p1.setBackground(Color.red);
b1.setBounds(40, 80, 80, 40);
p1.setBackground(Color.red);
b1.addActionListener(this);

this.add(b1);
this.add(p1);
this.setSize(350, 250);

this.setLayout(null);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}



@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub

if (e.getSource() == b1) {

if(p1.getBackground()==Color.red) {
p1.setBackground(Color.green);
}

else if(p1.getBackground()==Color.green) {
p1.setBackground(Color.blue);
}
else if(p1.getBackground()==Color.blue){
p1.setBackground(Color.red);
}







}
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.