Hallo leute,
Könnt ihr mir ein gefallen tun und euch diesen Code anschauen.Der Button rewrite funktioniert nicht richtig.
Danke
Könnt ihr mir ein gefallen tun und euch diesen Code anschauen.Der Button rewrite funktioniert nicht richtig.
Danke
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UpdateLibrary extends JFrame
implements ActionListener {
JTextField trackNo = new JTextField(2);
JTextField ratingNo = new JTextField(2);
TextArea information = new TextArea(8, 60);
JButton check = new JButton("Check Track");
JButton rewrite = new JButton("Update");
JButton addTrack = new JButton("Add New Track");
public UpdateLibrary() {
setLayout(new BorderLayout());
setBounds(610,610,610,270);
setTitle("Update Library");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel top = new JPanel();
top.add(new JLabel("Enter Track Number:"));
top.add(trackNo);
top.add(new JLabel("New Rating(1-5):"));
top.add(ratingNo);
top.add(check);
top.add(rewrite);
top.add(addTrack);
addTrack.addActionListener(this);
check.addActionListener(this);
rewrite.addActionListener(this);
add("North", top);
JPanel middle = new JPanel();
information.setText(LibraryData.listAll());
middle.add(information);
add("Center", middle);
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == check) {
String key = trackNo.getText();
String name = LibraryData.getName(key);
String artist = LibraryData.getArtist(key);
int ratingValue = Integer.parseInt(ratingNo.getText());
if (name == null) {
information.setText("No such track number");
}
else {
information.setText(name + " - " + LibraryData.getArtist(key));
information.append("\nRating: " + stars(LibraryData.getRating(key)));
information.append("\nPlay count: " + LibraryData.getPlayCount(key));
LibraryData.setRating(key,ratingValue);
}
if (e.getSource() == rewrite){
System.out.println("hahahaha");
//int rating = Integer.parseInt(ratingNo.getText());
//LibraryData.setRating(key,ratingValue);
}
}
}
private String stars(int Rating) {
String stars = "";
// line 77-79 for loop assigning a control variable to a starting value
// the test is carried out prior to any execution of the loop
// it increments the control variable by 1
for (int i = 0; i < Rating; ++i) {
stars += "*";
}
// line 81 returns the value
return stars;
}
}