You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
5.1 KiB
168 lines
5.1 KiB
|
|
|
|
/*
|
|
* import java.awt.BorderLayout; import java.awt.EventQueue;
|
|
*
|
|
* import javax.swing.JFrame; import javax.swing.JPanel; import
|
|
* javax.swing.border.EmptyBorder; import java.awt.Color; import
|
|
* javax.swing.JLabel; import javax.swing.JTextField; import
|
|
* javax.swing.JButton; import java.awt.Font; import javax.swing.SwingConstants;
|
|
* import java.awt.event.ActionListener; import java.awt.event.ActionEvent;
|
|
*
|
|
* public class Ratings extends JFrame {
|
|
*
|
|
* private JPanel contentPane; private JTextField textField; private JTextField
|
|
* textField_1; private JTextField textField_2; private JTextField textField_3;
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.EventQueue;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.border.EmptyBorder;
|
|
import java.awt.Color;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.JButton;
|
|
import java.awt.Font;
|
|
import javax.swing.SwingConstants;
|
|
import java.awt.event.ActionListener;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.awt.event.ActionEvent;
|
|
|
|
public class RatingsFrame extends JFrame {
|
|
|
|
private JPanel contentPane;
|
|
private JTextField tf_midR;
|
|
private JTextField tf_snameR;
|
|
private JTextField tf_relationR;
|
|
private JTextField tf_ratingsR;
|
|
|
|
|
|
/**
|
|
* Create the frame.
|
|
*/
|
|
public RatingsFrame() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
setBounds(100, 100, 589, 488); contentPane = new JPanel();
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane);
|
|
|
|
JPanel panel = new JPanel();
|
|
panel.setBackground(new Color(0, 0, 51));
|
|
contentPane.add(panel, BorderLayout.CENTER);
|
|
panel.setLayout(null);
|
|
|
|
JLabel lblNewLabel = new JLabel("Ratings Details");
|
|
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 24));
|
|
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
lblNewLabel.setForeground(new Color(255, 255, 255));
|
|
lblNewLabel.setBounds(148, 22, 247, 36); panel.add(lblNewLabel);
|
|
|
|
JLabel lblNewLabel_1 = new JLabel("Movie ID:");
|
|
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 16));
|
|
lblNewLabel_1.setForeground(new Color(255,255, 255));
|
|
lblNewLabel_1.setBounds(41, 87, 76, 14);
|
|
panel.add(lblNewLabel_1);
|
|
|
|
JLabel lblNewLabel_2 = new JLabel("Name Surname:");
|
|
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
|
|
lblNewLabel_2.setForeground(new Color(255,255, 255));
|
|
lblNewLabel_2.setBounds(41, 129, 127, 36);
|
|
panel.add(lblNewLabel_2);
|
|
|
|
JLabel lblNewLabel_3 = new JLabel("Relation:");
|
|
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 16));
|
|
lblNewLabel_3.setForeground(new Color(255,255, 255));
|
|
lblNewLabel_3.setBounds(41, 183, 76, 36);
|
|
panel.add(lblNewLabel_3);
|
|
|
|
JLabel lblNewLabel_4 = new JLabel("Ratings :");
|
|
lblNewLabel_4.setFont(new Font("Tahoma", Font.PLAIN, 16));
|
|
lblNewLabel_4.setForeground(new Color(255,255, 255));
|
|
lblNewLabel_4.setBounds(41, 245, 76, 17);
|
|
|
|
panel.add(lblNewLabel_4);
|
|
|
|
tf_midR = new JTextField(); tf_midR.setBounds(194, 86, 183, 20);
|
|
panel.add(tf_midR);
|
|
tf_midR.setColumns(10);
|
|
|
|
tf_snameR = new JTextField(); tf_snameR.setColumns(10);
|
|
tf_snameR.setBounds(194, 139, 179, 20); panel.add(tf_snameR);
|
|
|
|
tf_relationR = new JTextField(); tf_relationR.setColumns(10);
|
|
tf_relationR.setBounds(194, 193, 179, 20); panel.add(tf_relationR);
|
|
|
|
tf_ratingsR = new JTextField(); tf_ratingsR.setColumns(10);
|
|
tf_ratingsR.setBounds(194, 245, 183, 20);
|
|
panel.add(tf_ratingsR);
|
|
|
|
JButton btnaddR = new JButton("OK");
|
|
btnaddR.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
if(tf_midR.getText().isEmpty() || tf_relationR.getText().isEmpty() ||tf_ratingsR.getText().isEmpty() || tf_snameR.getText().isEmpty()) {
|
|
|
|
JOptionPane.showMessageDialog(null, "Please Enter All the Fields !!");
|
|
}
|
|
else{
|
|
Rating rt = new Rating();
|
|
rt.setMovieId(Integer.parseInt(tf_midR.getText()));
|
|
rt.setRelation(tf_relationR.getText());
|
|
rt.setNameSurname(tf_snameR.getText());
|
|
rt.setRating(Integer.parseInt(tf_ratingsR.getText()));
|
|
|
|
try {
|
|
|
|
FileWriter fw = new FileWriter( "C:\\Users\\skc\\eclipse-workspace\\first\\Favorite_Movies\\src\\files\\ratings_data.txt",true);
|
|
tf_midR.write(fw);
|
|
tf_snameR.write(fw.append(" "));
|
|
tf_relationR.write(fw.append(" "));
|
|
tf_ratingsR.write(fw.append(" "));
|
|
|
|
fw.write("\n");
|
|
|
|
fw.close();
|
|
|
|
JOptionPane.showMessageDialog(null, "Ratings added Successfully.....");
|
|
|
|
tf_midR.setText("");
|
|
tf_relationR.setText("");
|
|
tf_ratingsR.setText("");
|
|
tf_snameR.setText("");
|
|
|
|
} catch (IOException e1) { // TODO Auto-generated catch block
|
|
e1.printStackTrace(); }
|
|
}
|
|
}
|
|
});
|
|
btnaddR.setBounds(195, 320,89, 23); panel.add(btnaddR);
|
|
|
|
JButton btnHomeR = new JButton("Home");
|
|
btnHomeR.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
Main_HomePage mhp=new Main_HomePage();
|
|
mhp.setVisible(true);
|
|
if(mhp.isVisible()) { //use to display only one screen
|
|
RatingsFrame.this.dispose();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
});
|
|
|
|
btnHomeR.setBounds(304, 320, 89, 23);
|
|
panel.add(btnHomeR);
|
|
}
|
|
}
|
|
|
|
|
|
|