ads

Menu Bar

Horizontal Scrollable Menu

Search This Blog

Java swing | Jpanel with Calculator mini Project | Source code - myprogrammingschool

Java swing | Jpanel with Calculator mini Project

A part of the Java Swing package JPNL is a container that can store a set of components. The main function of JPanel is to organize the components, various layouts can be defined in JPanel that provide better organization of components, although it does not have a title bar.

Manufacturers of JPanel are:

JPanel (): Creates a new panel with flow layout
JPanel (LayoutManager l): Creates a new JPanel with the specified Layout Manager
JPanel (boolean isDoubleBuffered): Creates a new JPanel with a specified buffering strategy
JPanel (LayoutManager l, boolean isDoubleBuffered): Creates a new JPanel with a specified layout manager and a specified buffering strategy
Common Functions:

add (component c): adds a component to a specified container
setLayout (LayoutManager l): sets the layout of the container to the specified layout manager
updateUI (): Resets the UI property with values ​​from the current look and feel.
SetUI (Panelui UI): Look and feel the object presenting this component.
getUI (): Looks and feels the object presenting this component.
paramString (): Returns a string representation of this JPanel.
getUIClassID (): gives the name of the Look and Feel class representing this component.
getAccessibleContext (): AccessibleContext is associated with this JPanel.
Program to describe the use of JPanel
1. Add a component to the program to create a simple JPanel

Source code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class AddJanel implements ActionListener
{
JFrame f;
JPanel o=new JPanel();
JTextField t1,t2,t3;
JButton b1,b2,b3,b4,b5,b6;
AddJanel()
{
f=new JFrame(" fream");
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
b3=new JButton("++");
b4=new JButton("--");
b5=new JButton("**");
b6=new JButton("/");
b1=new JButton("Reset");
b2=new JButton("Cancel");

f.setVisible(true);
f.setLayout(new BorderLayout());
f.setSize(400,400);

f.add(b1,BorderLayout.EAST);
f.add(b2,BorderLayout.WEST);
f.add(t1,BorderLayout.NORTH);
f.add(t2,BorderLayout.SOUTH);
f.add(o,BorderLayout.CENTER);
o.setLayout(new BorderLayout());
o.setVisible(true);
o.setSize(100,100);

o.add(b3,BorderLayout.EAST);
o.add(b4,BorderLayout.WEST);
o.add(b5,BorderLayout.SOUTH);
o.add(b6,BorderLayout.NORTH);
o.add(t3,BorderLayout.CENTER);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int a,b;
a=Integer.parseInt(t1.getText());
b=Integer.parseInt(t2.getText());

if(e.getSource().equals(b3))
{
int c=a+b;
t3.setText(String.valueOf(c));
}

else if(e.getSource().equals(b4))
{
int c=a-b;
t3.setText(String.valueOf(c));
}



else if(e.getSource().equals(b5))
{
int c=a*b;
t3.setText(String.valueOf(c));
}


else if(e.getSource().equals(b6))
{
int c=a/b;
t3.setText(String.valueOf(c));
}

else if(e.getSource().equals(b1))
{
t1.setText("");
t2.setText("");
t3.setText("");
}

else
{
f.setVisible(false);
}
}

public static void main(String []ss)

{
new AddJanel();
}
}

OUTPUT




For more project click here

How to make Calculator using java Swing , gui application| mini Project - myprogrammingschool

How to make Calculator using java Swing , gui application| mini Project - myprogrammingschool

Swing API is a set of extensible GUI components to make a developer life easier for building JAVA based front end / GUI applications. It is built over the AWT API and serves as a replacement for the AWT API as it has almost every control corresponding to the AWT controls. The swing component follows a model-view-controller architecture to meet the following criteria.

A single API should suffice for multiple types of look and feel.
The API is modeled so that the highest level of API is not required for the data.
The API is to use the Java Bean model so that builder tools and IDEs can provide better services to developers to use.

Here you can do different arithmetic operation like addition , subtraction , multiplication and division

Source code of Calculator

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class Calculater extends Applet implements ActionListener
{
//Frame f;
Frame f=new Frame();
Label l1=new Label("enter 1st number");
Label l2=new Label("enter 2nd number");
Label l3=new Label("Result");
TextField t1=new TextField();
TextField t2=new TextField();
TextField t3=new TextField();
Button b1=new Button("Add");
Button b2=new Button("Sub");
Button b3=new Button("Mult");
Button b4=new Button("div");
Button b5=new Button("cancel");
Calculater()
{
l1.setBounds(50,100,100,20);
l2.setBounds(50,130,100,20);
l3.setBounds(50,170,100,20);
t1.setBounds(200,100,100,20);
t2.setBounds(200,140,100,20);
t3.setBounds(200,180,100,20);
b1.setBounds(10,250,100,20);
b2.setBounds(100,250,100,20);
b3.setBounds(200,250,100,20);
b4.setBounds(300,250,100,20);
b5.setBounds(400,250,100,20);
f.setLayout(null);
f.setVisible(true);
f.setSize(600,400);
f.add(l1);
f.add(t1);
f.add(l2);
f.add(t2);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(l3);
f.add(t3); 
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
//f.setlayout(null);
//f.setVisible(true);
//f.setSize(400,350);
}
public void actionPerformed(ActionEvent ee)
{
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
if(ee.getSource().equals(b1))
{
t3.setText(String.valueOf(n1+n2));
}

if(ee.getSource().equals(b2))
{
t3.setText(String.valueOf(n1-n2));
}

if(ee.getSource().equals(b3))
{
t3.setText(String.valueOf(n1*n2));
}

if(ee.getSource().equals(b4))
{
t3.setText(String.valueOf(n1/n2));
}
if(ee.getSource().equals(b5))
{
System.exit(0);
}
}
 public static void main(String [] args)
{
new Calculater();
}
}


if you want to see more project click here

Python Comment | Creating a Comment | multiline comment | example

 Python comment

Comments will be used to create a case for Python code.


Comments will be used to make the code more legible.


Once the code is tested, comments will not stop execution.


Make a comment


Comments begin with #, and Python may ignore them:


Examples

# This can be a comment

Print ("Hello, World!")


Comments will be placed at the top of a line, and Python may ignore the rest of the line:


Examples

Print ("Hello, World!") # This could be a comment


Comments could not find the text to clarify the code, this may also be used to prevent Python from executing code:


Examples

#print ("Hello, World!")

Print ("Cheers, Met!")


Multi line comments

Python does not have a syntax for multi-line comments.


To add a multi line comment, you can insert a # for each line:


Examples

# This can be a comment # One line has # more written ("Hello, World!"


Or, almost as mean, you would use a multi-line string.


Since Python can ignore string literals that are not assigned to a variable, you will add a multi-line string (triple quotes) to your code, and you will comment within:


Examples


"""
This is a comment

written in

More than just one line

"""       

Print ("Hello, World!")


Python can browse the code until the string is allocated to a variable, ignore it on the other side, and you have created a multi-line comment.

Happy Ganesh Chaturthi

Happy Ganesh Chaturthi


 Happy Ganesh Chaturthi


 Send heat desires and much of affection on this Ganesa Chaturthi to your family and friends with our greatest assortment of Happy Ganesa Chaturthi 
Ganesha Chaturthi, the nice Ganapati competitionadditionally called ‘Vinayak Chaturthi’ or ‘Vinayaka Chavithi’ is widely known by Hindus round the world because the birthday of Lord Ganapati.
He is the younger son of Lord Shiva and goddess Parvati.
Lord Ganapati is that the God of prosperity and his blessings bring fruitful and prosperous outcome within the family.
Here we’ve compiled Lord Ganpati Sms in Hindi, Happy Ganesa Chaturthi Sms, Vinayaka Chavithi Sms for Whatsapp & Facebook friends, sacred Happy Ganesa Chaturthi Shayari, Vinayagar Chaturthi desires, गणेश
चतुर्थी शायरी मैसेज or विशेष, गणपति इमेज, गणेश जी फोटो, a pair of Line Bhagwan Ganesa Quotes in Hindi, psychological feature Lord Ganesa Chaturthi Messages in Hindi & English for acknowledgement Cards, Cute
Ganpati Wishes Messages for Kids & Children etc. Wish you Happy Ganesh Chaturthi 2019

Canteen food order ,generate total bill using java swing | Gui application, mini Project , java

Canteen food order ,generate total bill using java swing | Gui application, mini Project





Here you can select food categories and number of item  then after order you can generate total bill 
////
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
public class CanteenT implements ActionListener

JFrame f;
JTabbedPane tb;
CanteenT()
{
f=new JFrame("Canteen");
tb=new JTabbedPane();
f.setVisible(true);
f.setSize(1500,1500);
tb.addTab("Veg",new Veg());
tb.addTab("Nonveg",new Nonveg());
tb.addTab("Bill",new Bill());
f.add(tb);
}
public void actionPerformed(ActionEvent ae)
{
}
public static void main(String...aa)
{
new CanteenT();
}
}



class Veg extends JPanel implements ActionListener
{
JButton b1;
JLabel l1,l2,l3,l4;
JTextField t1,t2;
Veg()
{
b1=new JButton("Bill");
l1=new JLabel("Idli:25 ");
l2=new JLabel("Dosa:30");
l3=new JLabel("Enter quantity");
l4=new JLabel("Enter quantity");
t1=new JTextField(10);
t2=new JTextField(10);
add(l1);
add(l3);
add(t1);
add(l2);
add(l4);
add(t2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(b1))
{int c;
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
c=(a*25)+(b*30);
String h=String.valueOf(c);
try
{
FileWriter x=new FileWriter("bill1.txt");
{
x.write(h);
x.close();
}
}
catch(IOException jj)
{}
}
}
}


class Nonveg extends JPanel implements ActionListener
{
JButton b1;
JLabel l1,l2,l3,l4;
JTextField t1,t2;
Nonveg()
{
b1=new JButton("Bill");
l1=new JLabel("Chicken:150 ");
l2=new JLabel("Mutton:430");
l3=new JLabel("Enter quantity");
l4=new JLabel("Enter quantity");
t1=new JTextField(10);
t2=new JTextField(10);
add(l1);
add(l3);
add(t1);
add(l2);
add(l4);
add(t2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(b1))
{int c1;
int a1=Integer.parseInt(t1.getText());
int b1=Integer.parseInt(t2.getText());
c1=(a1*150)+(b1*430);
String h1=String.valueOf(c1);
try
{
FileWriter y=new FileWriter("bill2.txt");
{
y.write(h1);
y.close();
}
}
catch(IOException jj)
{}
}
}
}
class Bill extends JPanel implements ActionListener
{
JLabel l1;
JTextField t1;
JButton b1;
Bill()
{
l1=new JLabel("Your bill is");
t1=new JTextField(10);
b1=new JButton("Bill");
add(l1);
add(t1);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource().equals(b1))
{try
{
InputStream is=new FileInputStream("bill1.txt");
BufferedReader buf=new BufferedReader(new InputStreamReader(is));
String hjk=buf.readLine();
int kk=Integer.parseInt(hjk);
InputStream is1=new FileInputStream("bill2.txt");
BufferedReader buf1=new BufferedReader(new InputStreamReader(is1));
String k=buf1.readLine();
int jk=Integer.parseInt(k);
int f=kk+jk;
t1.setText(String.valueOf(f));
}
catch(Exception fd)
{}
}
}
}

Currency Conveter java project, swing component ,| Gui application

currency converter java project, swing component ,| Gui application


This is mini project which is done by student in this you can convert the currency from one form to another. simple code for currency conveter java project .
//
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
class CurrencyConveter extends JFrame implements ActionListener
{
JFrame f;
JLabel l1,l2;
JTextField t1,t2;
JButton b1,b2;
JComboBox c1,c2;

CurrencyConveter()
{
f=new JFrame("Currency Conveter");

String[] currency={"US Dollar","Indian Rupee","British Pound","Euro","Chinese Yuan"};
c1=new JComboBox(currency);
c1.setSelectedIndex(0);
c1=new JComboBox(currency);
//c2.setSelctedIndex(1);

l1=new JLabel("enter your currency");
l2=new JLabel("conveted currency is:");

CheckboxGroup g=new CheckboxGroup(); 
Checkbox i=new Checkbox("India",g,true);
Checkbox u=new Checkbox("usa",g,false);
Checkbox n=new Checkbox("Nepal",g,false);
Checkbox m=new Checkbox("Malaysia",g,false);


t1=new JTextField(10);
t2=new JTextField(10);

b1=new JButton("convert");
b2=new JButton("cancel");

f.setVisible(true);
f.setSize(400,400);
f.setLayout(new FlowLayout());

f.add(l1);
f.add(t1);
f.add(b1);
f.add(b2);
f.add(l2);
f.add(t2);

b1.addActionListener(this);
b2.addActionListener(this);

}
public void actionPerformed(ActionEvent e)
{
}





public static void main(String []pp)
{
new CurrencyConveter();
}

}

Insert method , Remove Data From List , Remove Item From Position or from index , Remove method , Delete statement , Looping in list In Python

Insert method

Python list method insert () inserts object obj
 into the insert list.
Syntax

Following is the syntax to insert () method -

List. List (index, obj)

Parameter

     Index - This is the index where the object 
object needs to be inserted.

     obj - This is the item to be inserted in the
 given list.

return value

This method does not return any value, but it
 inserts the given element into the given index.
mixed.insert(0,'zero')

print(mixed)

Remove Data From List

The remove () method removes the object passed as
 an argument. If you need to remove elements based
 on the index (such as the fourth element or the 
last element), you can use the pop () method. In
addition, you can use the Dell statement to remove
items from a list or to delete an entire list.

popped=mixed.pop()

print(popped)            # OutPut = 9

print(mixed)            
 # OutPut = [1, 2, 3, [4, 5, 6], 'seven', 8.0]

Remove Item From Position or from index

example:

popped = mixed.pop(4)

print(popped)              # outPut = seven

print(mixed)
# OutPut = [1, 2, 3, [4, 5, 6], 8.0, 9]

Remove method

example:
print(mixed)                
# OutPut = [1, 2, 3, [4, 5, 6], 'seven', 8.0, 9]

mixed.remove('seven')      # OutPut = seven

print(mixed)  
 # OutPut = [1, 2, 3, [4, 5, 6], 8.0, 9]

Delete statement

# delete method is use to delete the element 
present in list

del mixed[6]

print(mixed)                   # OutPut = 9

Looping in list


for i in mixed:
    print(i)

    OUtPut
123[4, 5, 6]
seven
8.09

ads3