All pastes #10593 Raw Edit

warren

public java v1 · immutable
#10593 ·published 2005-04-29 20:26 UTC
rendered paste body
import java.awt.*;import java.applet.*;import java.awt.event.*;public class BookApplet extends Applet implements ActionListener{	//Declare panels	Panel myInputPanel = new Panel();	Panel myButtonPanel = new Panel();	Panel myHeaderPanel = new Panel();	Panel myResultPanel = new Panel();	Color myColor = new Color(80,175,130);	Font myFont = new Font("Arial",1,18);	//declare all button and labels	private TextField myTextField1 = new TextField(15);	private TextField myTextField2 = new TextField(15);	private TextField myTextField3 = new TextField(15);	private TextField myTextField4 = new TextField(15);	private Button myButton1 = new Button("Enter Book");	private Button myButton2= new Button("Clear Screen");	private Button myButton3= new Button("Average Book price");	private Label myLabel1  = new Label("Enter book ID",1);	private Label myLabel2  = new Label("Enter book name",1);	private Label myLabel3  = new Label("Enter number of books",1);	private Label myLabel4  = new Label("Enter price of the book",1);	private Label myResult1 = new Label("",1);	private Label myResult2 = new Label("",1);	private Label myHeader = new Label("Welcome to myBook Screen",1);	private Book myBook;	private BookList myBookList = new BookList(3);	public BookApplet()	//Add the action listener to the button and labels	{	 myHeaderPanel.add(myHeader);	 myInputPanel.setLayout (new GridLayout(4,2));	 myResultPanel.setLayout (new GridLayout(2,2));	 myHeader.setFont(myFont);	 myHeaderPanel.setForeground(myColor);	 myInputPanel.add(myLabel1);	 myInputPanel.add(myTextField1);	 myInputPanel.add(myLabel2);	 myInputPanel.add(myTextField2);	 myInputPanel.add(myLabel3);	 myInputPanel.add(myTextField3);	 myInputPanel.add(myLabel4);	 myInputPanel.add(myTextField4);	 myButtonPanel.add(myButton1);	 myButtonPanel.add(myButton2);	 myButtonPanel.add(myButton3);	 myResultPanel.add(myResult1);	 myResultPanel.add(myResult2);	 this.myButton1.addActionListener(this);	 this.myButton2.addActionListener(this);	 this.myButton3.addActionListener(this);	 myButton1.addActionListener(this);	 myButton2.addActionListener(this);	 myButton3.addActionListener(this);	 add(myHeaderPanel);	 add(myInputPanel);	 add(myButtonPanel);	 add(myResultPanel);	}	public void loadBook()		{			myBook = new Book(myTextField1.getText(),myTextField2.getText());			myBook.enterdetails(myTextField3.getText(),myTextField4.getText());			if(myBookList.add(myBook))			{				myResult1.setText("The Book has been Loaded");			}			else			{				myResult1.setText("There's no more space in the array");			}		}	public void clearScreen()	{		myTextField1.setText("");		myTextField2.setText("");		myTextField3.setText("");		myTextField4.setText("");	}	public void actionPerformed(ActionEvent e)	{		String myAverage;		if(e.getSource()==myButton1)		{				loadBook();				clearScreen();		}		if(e.getSource()==myButton3)		{			  if (myStudent!=null)			   {				 myAverage = "Student Average is: " + myStudent.calculateAverage();				 myResult1.setText(myAverage);		}		   else		{			myResult1.setText("No Student has been loaded");		}		 }		if(e.getSource()==allAveragesButton)		    {				myResult2.setText("The average for all the books is" + myBookList.BookListAverage());		}	}	}	{}