Posts

Showing posts from August, 2020

Java Program to find average of Three numbers

 import java.util.Scanner; class Average{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("How many numbers are you goind to add"); int num = sc.nextInt(); int[] numbers = new int[num]; System.out.println("Enter the numbers one by one by pressing enter"); for(int i=0; i<num; i++){ numbers[i] = sc.nextInt(); } double avg=0; int sum =0; for(int i=0; i<num; i++){ sum = sum+numbers[i]; } avg=sum/num ; System.out.println("the avg is"+avg); } }

Java Program any letter to upper case Letter(JavaSWING) ActionListener

Image
import java.awt.event.*; import java.awt.*; import javax.swing.*; class MyFrame extends JFrame implements ActionListener{ Container c; JTextField t1; JButton b1; MyFrame(){ c=this.getContentPane(); c.setLayout(null); t1 = new JTextField(); t1.setBounds(100,50,210,50); c.add(t1); b1 = new JButton("CLick"); b1.setBounds(100,100,150,40); c.add(b1); b1.addActionListener(this); } public void actionPerformed(ActionEvent e){ String str =t1.getText(); t1.setText(str.toUpperCase()); } } class Uper{ public static void main(String[] args) { MyFrame f = new MyFrame(); f.setBounds(100,100,800,400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle("to upper case"); f.setVisible(true); } } 

Java Swing Complete examples step by step(make a project with swing)

Image
 FIRST PROGRAM(JFRAME): import java.awt.*; import javax.swing.*; class MyFirstFrame{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("My First frame"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(50,100,800,500); //for changing the icon we need create object of ImageIcon ImageIcon img = new ImageIcon("bikas.jpg"); frame.setIconImage(img.getImage()); Container c = frame.getContentPane(); //c.setBackground(Color.RED); c.setBackground(new Color(80, 149, 80)); } } OUTPUT:  Second  PROGRAM(JLABEL): import java.awt.*; import javax.swing.*; class MyLabel{ public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("JAVA"); frame.setBounds(50,250,1000,800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Container c=frame.getContentPane(); c.setLayout(null); /...