import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.lang.*;
import java.util.*;
import java.io.*;



public class PaymentNewGUI extends JFrame{
	
	private JButton tenP, twentyP, fiftyP, onePound, twoPound, payButton;
	JTextField ticketID;
	
	
	Label lEntranceTime;
	Label lPaymentTime;
	Label lTimeDifference;
	Label lDue;
	Label lInserted;
	Label lMessage = new Label("Enter Your Ticket Number");
	Container content;
	JPanel ticketPanel;
	JPanel coins;
	
	/***Key Variable***/
	long entranceTime;
	long paymentTime;
	String ticketStatus;
	double amountInserted =0.00;
	double balance =0.00;
	int ticketIDNumber;
	long diffHours;
	
	
		
	
	public PaymentNewGUI() {
		
		lEntranceTime = new Label("Entrance Time: " );
		lPaymentTime = new Label("Payment Time: " );
		lTimeDifference = new Label("Duration: " );
		lDue = new Label("Amount Due:   \u00A3" + balance);
		lInserted = new Label("Amount Instered:   \u00A3" + amountInserted);
		
		
		content = getContentPane();
		content.setLayout(new BorderLayout());
		this.setTitle("Enter Ticket Information");
	 	
		Label lTicketID = new Label("Enter Ticket No:");
		JButton enterButton = new JButton("Enter");
		enterButton.addActionListener(new enterListener());

				payButton = new JButton("Pay Now");
					payButton.addActionListener(new payListener());
						

		ticketID = new JTextField(9);
		ticketPanel = new JPanel();
    	ticketPanel.setLayout(new GridLayout(0,1));
		ticketPanel.add(lTicketID);
		ticketPanel.add(ticketID);
		ticketPanel.add(enterButton);
		ticketPanel.add(lMessage);
		ticketPanel.add(payButton);
		payButton.setEnabled(false);
		ticketPanel.setVisible(true);
		content.add(ticketPanel, BorderLayout.NORTH);
		
		coins = new JPanel();
    	coins.setLayout(new GridLayout(0,1));
    	ImageIcon tenP = new ImageIcon("10p.jpeg");
    	tenP = new JButton("", tenP);
    	ImageIcon twentyP = new ImageIcon("20p.jpeg");
    	twentyP = new JButton("", twentyP);
    	ImageIcon fiftyP = new ImageIcon("50p.jpeg");
    	fiftyP = new JButton("", fiftyP);
    	ImageIcon pound = new ImageIcon("pound.jpeg");
    	onePound = new JButton("", pound);
    	//ImageIcon 2pound = new ImageIcon("2pound.jpeg");
    //	twoPound = new JButton("", 2pound);
    	
    	
    	
    	coins.add(tenP);
    	coins.add(twentyP);
    	coins.add(fiftyP);
    	coins.add(onePound);
    	coins.add(twoPound);
    	coins.setVisible(true);
    	//coins.setEnabled(false);
    	content.add(coins, BorderLayout.EAST);
    	 
		
		
		
		/*********************Label Addition to Frame Content***********************/
		JPanel labelPanel = new JPanel();
		labelPanel.setLayout(new GridLayout(4,0));
		labelPanel.setVisible(true);
		labelPanel.add(lEntranceTime);
		labelPanel.add(lPaymentTime);
		labelPanel.add(lTimeDifference);
		labelPanel.add(lDue);
		labelPanel.add(lInserted);
		content.add(labelPanel, BorderLayout.CENTER);
		/*********************Label Only*************************/
		
		
	}//end PaymentNewGUI constructor

	/*********************Ticket Number Listener and Display Ticket Information************************************/
	
	public class enterListener implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			
			Ticket ticket = new Ticket();
			ticketIDNumber = Integer.parseInt(ticketID.getText());
			String loadMessage = ticket.loadTicket(ticketIDNumber);

			lMessage.setText(loadMessage);

			
			entranceTime = Ticket.entranceTime;
			paymentTime = Ticket.paymentTime;
			ticketStatus = Ticket.ticketStatus;
		    balance = Ticket.balance;
			
			if (loadMessage.equals("The Ticket has loaded successfully.")){
				
				SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
				Date resultdate = new Date(entranceTime); //entrance time hold the time in Miliseconds, convert to show in time date format
				lEntranceTime.setText("Entrance Time: " + sdf.format(resultdate)); 
//It wont show up here.

						 payButton.setEnabled(true);
				
	    	} else  {
	    		lMessage.setText(loadMessage);
	    		
		}
		}}
	/*********************Ticket Number Listener************************************/
	
	
	
	/*********************Pay Button Listener***************************************/
	public class payListener implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			
			replace();
			Ticket getNewPayTime = new Ticket();
			getNewPayTime.loadTicket(ticketIDNumber);
			paymentTime = Ticket.paymentTime; //getting correct ticket pyament time, correction performed by replace method. 
			
			long timeDifference = paymentTime - entranceTime;
			
			SimpleDateFormat sdf1 = new SimpleDateFormat("MMM dd,yyyy HH:mm");
			Date paymentdate = new Date (paymentTime);
			lPaymentTime.setText("Payment Time: " + sdf1.format(paymentdate));
			
			long diffSeconds = timeDifference / 1000;
			long diffMinutes = timeDifference / (60 * 1000);
			diffHours = timeDifference / (60 * 60 * 1000);
			
			lTimeDifference.setText("Duration Parked: "+""+diffHours+":"+diffMinutes+":"+diffSeconds);
			
			
			
			}
		}
	/*********************Pay Button Listener***************************************/
	
	
 /*********************************Payment Time Calculation Method*****************************/
	   public void replace() {
	      String oldFileName = "Ticket/"+ticketIDNumber+".dat";
	      String tmpFileName = "Ticket/tmp_"+ticketIDNumber+".dat";

	      BufferedReader br = null;
	      BufferedWriter bw = null;
	      try {
	         br = new BufferedReader(new FileReader(oldFileName));
	         bw = new BufferedWriter(new FileWriter(tmpFileName));
	         String line;
	         while ((line = br.readLine()) != null) {
	            if (line.contains("1313131"))
	               line = line.replace("1313131", ""+System.currentTimeMillis());
	                bw.write(line+"\n");
	         }
	      } catch (Exception e) {
	         return;
	      } finally {
	         try {
	            if(br != null)
	               br.close();
	         } catch (IOException e) {
	            //
	         }
	         try {
	            if(bw != null)
	               bw.close();
	         } catch (IOException e) {
	            //
	         }
	      }
	      // Once everything is complete, delete old file..
	      File oldFile = new File(oldFileName);
	      oldFile.delete();

	      // And rename tmp file's name to old file name
	      File newFile = new File(tmpFileName);
	      newFile.renameTo(oldFile);
	      
	   }
	    
/*********************************Payment Time Calculation Method*****************************/	
	
	
	      
	      

	
	public static void main(String args[]) {
		PaymentNewGUI frame = new PaymentNewGUI();
		frame.pack();
		frame.setVisible(true);
		frame.setSize(650,350);
		}
	
	
	
}

Hello i am trying to add image as buttons why am i getting these compiling errors

found   : javax.swing.JButton
required: javax.swing.ImageIcon
        tenP = new JButton("", tenP);
               ^
PaymentNewGUI.java:78: incompatible types
found   : javax.swing.JButton
required: javax.swing.ImageIcon
        twentyP = new JButton("", twentyP);
                  ^
PaymentNewGUI.java:80: incompatible types
found   : javax.swing.JButton
required: javax.swing.ImageIcon
        fiftyP = new JButton("", fiftyP);
                 ^
PaymentNewGUI.java:88: cannot find symbol
symbol  : method add(javax.swing.ImageIcon)
location: class javax.swing.JPanel
        coins.add(tenP);
             ^
PaymentNewGUI.java:89: cannot find symbol
symbol  : method add(javax.swing.ImageIcon)
location: class javax.swing.JPanel
        coins.add(twentyP);
             ^
PaymentNewGUI.java:90: cannot find symbol
symbol  : method add(javax.swing.ImageIcon)
location: class javax.swing.JPanel
        coins.add(fiftyP);
             ^
ImageIcon tenP = new ImageIcon("10p.jpeg");
tenP = new JButton("", tenP);   (etc)

You declare tenP to be an ImageIcon, OK, but then you try to assign a JLabel to that variable, not OK.
You need to create a different variable for the JLabel itself.

ImageIcon tenP = new ImageIcon("10p.jpeg");
tenP = new JButton("", tenP);   (etc)

You declare tenP to be an ImageIcon, OK, but then you try to assign a JLabel to that variable, not OK.
You need to create a different variable for the JLabel itself.

thank you after changing that the images are not displaying as buttons, instead its just normal gui buttons?

The thing that often goes wrong with ImageIcon is this:
new ImageIcon("somefile") does NOT throw an Exeception if it can't find the file, it just returns null. Then new JButton("some text", anImageIcon) does NOT throw an Exception if the image icon is null, it just doesn't display anything. So no errors flagged, you just don't get an image.
That is usually caused by Java looking for the file in the wrong directory.
Test this by
1. Printing the ImageIcon to see if it's null
2, Using a full path, starting from the drive letter, for the file.

This article has been dead for over six months. Start a new discussion instead.