top of page

Movie Ticket Booking Java Applet program

Updated: Mar 17, 2021



Required files:

make three txt files

50.txt, 100.txt,150.txt

Content of files;


"50.txt"
111111111111111111111111111111

111111111111111111111111111111
 
"100.txt"
2222222222222222222222222222222222222222222
 
"150.txt"
333333333333333333333333333333333333333333333333333
 

Java Program:


//MovieTicket1.java
 
import java.awt.*;

import java.applet.*;

import java.awt.event.*;

import java.io.*; 

import java.lang.*;


/* <applet code="MovieTicket1" width=600 height=400>

</applet>

*/

public class MovieTicket1 extends Applet implements ActionListener{


String msg="";

//static int c50=0,c100=0,c150=0;
public void init(){

        int c50=check("50.txt");

        int c100=check("100.txt");

        int c150=check("150.txt");

    //final Button    b=new Button[c50];

    //final Button    c=new Button[c100];

    //final Button    d=new Button[c150];

    for(int i=0;i<c50;i++){

        Button b=new Button("50");

        b.setBackground(Color.red);

        b.addActionListener(this);

        add(b);
 

    }
        for(int i=0;i<c100;i++){

            Button c=new Button("100");

            c.setBackground(Color.green);

            c.addActionListener(this);

            add(c);
 

        }

        for(int i=0;i<c150;i++){

            Button d=new Button("150");

            d.setBackground(Color.blue);

            d.addActionListener(this);

            add(d);
 

        }
}

public void actionPerformed(ActionEvent ae){

    String str=ae.getActionCommand();

    Button b1;
 

        if(str.equals("50") )

        {msg="Booked 50 Rs/";b1=(Button)ae.getSource();b1.setEnabled(false);}
 

        else if(str.equals("100"))

        {    msg="Booked 100 Rs/";b1=(Button)ae.getSource();b1.setEnabled(false);}
        else if(str.equals("150"))

            {msg="Booked 150/";b1=(Button)ae.getSource();b1.setEnabled(false);}                                    

    repaint();

}
public int check(String file){

    int count=0;
     try{  

           FileInputStream fin=new FileInputStream(file);  

            int i=0;  

            while((i=fin.read())!=-1){  

                         count++; 

                }  

            fin.close();  

      }catch(Exception e){} 
 

return count;

}

public void paint(Graphics g){

    g.drawString(msg,200,400);

}

}

Create a file with MovieTicket1.java and copy and paste the above code and create the three files and put over there in same folder.

1. Compile the "MovieTicket1.java"

javac MovieTicket1.java

2. Run the program from Cmd:

appletviewer MovieTicket1.java

Note: The numbers of characters in each files represent the the numbers of button will be created of that respectively.

"1" for 50Rs

"2" for 100Rs

"3" fro 150 Rs

Button will be generated on screen accordingly the character each of files have.





bottom of page