#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Exclamation Urgent Help!!! Can Someone Explain What And How This Code Works Please Asap!!!


    IF YOU CANT EXPLAIN ALL SOME WILL DO
    URGENT!!

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    //
    public class CheckLibrary extends JFrame
    implements ActionListener {
    JTextField trackNo = new JTextField(2);
    TextArea information = new TextArea(6, 50);
    JButton list = new JButton("List All Tracks");
    JButton check = new JButton("Check Track");
    public CheckLibrary() {
    setLayout(new BorderLayout());
    setBounds(100, 100, 400, 200);
    setTitle("Check Library");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JPanel top = new JPanel();
    top.add(new JLabel("Enter Track Number:"));
    top.add(trackNo);
    top.add(check);
    top.add(list);
    list.addActionListener(this);
    check.addActionListener(this);
    add("North", top);
    JPanel middle = new JPanel();
    information.setText(LibraryData.listAll());
    middle.add(information);
    add("Center", middle);

    setResizable(false);
    setVisible(true);
    }
    //
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == list) {
    information.setText(LibraryData.listAll());
    } else {
    String key = trackNo.getText();
    String name = LibraryData.getName(key);
    if (name == null) {
    information.setText("No such track number");// output when the input was wrong such as entring the track number or artist name.
    } else {
    information.setText(name + " - " + LibraryData.getArtist(key));
    information.append("\nRating: " + stars(LibraryData.getRating(key)));
    information.append("\nPlay count: " + LibraryData.getPlayCount(key));
    }
    }
    }

    private String stars(int rating) {
    String stars = "";
    for (int i = 0; i < rating; ++i) {
    stars += "*";
    }
    return stars;
    }
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,717
    Rep Power
    348

IMN logo majestic logo threadwatch logo seochat tools logo