|
| 1 | +package dashboard; |
| 2 | + |
| 3 | +import java.awt.BorderLayout; |
| 4 | +import java.awt.Color; |
| 5 | +import java.awt.Dimension; |
| 6 | +import java.awt.Font; |
| 7 | +import java.awt.event.ActionEvent; |
| 8 | +import java.awt.event.ActionListener; |
| 9 | +import java.util.ArrayList; |
| 10 | +import javax.swing.JButton; |
| 11 | +import javax.swing.JFrame; |
| 12 | +import javax.swing.JLabel; |
| 13 | +import javax.swing.JPanel; |
| 14 | +import javax.swing.SwingConstants; |
| 15 | + |
| 16 | +public class NextQuoteClicked implements ActionListener{ |
| 17 | + private JButton nextQuote; |
| 18 | + private JLabel textLabel; |
| 19 | + private JFrame frame; |
| 20 | + private static ArrayList<Quote> quotesList; |
| 21 | + int quoteUpTo = 0; |
| 22 | + @Override |
| 23 | + public void actionPerformed(ActionEvent e) { |
| 24 | + if(e.getSource() == nextQuote) { |
| 25 | + setupQuotePanel(); |
| 26 | + //this.setTextLabel(textLabel); |
| 27 | + likeAndDislikeButtons(); |
| 28 | + likeAndDislikeButtonsClicked(); |
| 29 | + setupFrame(); |
| 30 | + nextQuotepanel.setVisible(true); |
| 31 | + } |
| 32 | + |
| 33 | + } |
| 34 | + |
| 35 | + public void setupQuotePanel() { |
| 36 | + //ButtonClicked.getPanel().setVisible(false); |
| 37 | + JPanel nextQuotepanel = new JPanel(); |
| 38 | + nextQuotepanel.setBackground(Color.gray); |
| 39 | + textLabel = new JLabel("<html>"+quotesList.get(quoteUpTo).toString()+"</html",SwingConstants.CENTER); |
| 40 | + quoteUpTo++; |
| 41 | + if(quoteUpTo > quotesList.size() -1) { |
| 42 | + quoteUpTo = 0; |
| 43 | + } |
| 44 | + textLabel.setFont(new Font("Magneto Bold", Font.BOLD,20)); |
| 45 | + textLabel.setPreferredSize(new Dimension(1000,100)); |
| 46 | + textLabel.setForeground(Color.pink); |
| 47 | + nextQuotepanel.add(textLabel, BorderLayout.LINE_START); |
| 48 | + } |
| 49 | + |
| 50 | + public void likeAndDislikeButtons() { |
| 51 | + JButton like=new JButton("Like"); |
| 52 | + like.setBackground(Color.pink); |
| 53 | + |
| 54 | + JButton dislike=new JButton("Dislike"); |
| 55 | + dislike.setBackground(Color.pink); |
| 56 | + |
| 57 | + like.setBounds(500,400,100,40); //dimensions where the button should go |
| 58 | + dislike.setBounds(800,400,100,40); // dimensions where the button should go. |
| 59 | + |
| 60 | + nextQuotepanel.add(like); |
| 61 | + nextQuotepanel.add(dislike); |
| 62 | + } |
| 63 | + |
| 64 | + public void likeAndDislikeButtonsClicked() { |
| 65 | + DislikeClicked dislikeClicked = new DislikeClicked(); |
| 66 | + dislikeClicked.setDislike(dislike); |
| 67 | + dislikeClicked.setFrame(frame); |
| 68 | + |
| 69 | + LikeClicked likeClicked = new LikeClicked(); |
| 70 | + likeClicked.setLike(like); |
| 71 | + likeClicked.setFrame(frame); |
| 72 | + |
| 73 | + like.addActionListener(likeClicked); |
| 74 | + dislike.addActionListener(dislikeClicked); |
| 75 | + } |
| 76 | + |
| 77 | + public void setupFrame() { |
| 78 | + frame.getContentPane().add(nextQuotepanel, BorderLayout.CENTER); |
| 79 | + frame.setContentPane(nextQuotepanel); |
| 80 | + frame.pack(); |
| 81 | + frame.setLocationByPlatform(true); |
| 82 | + } |
| 83 | + |
| 84 | + public void setNextQuote(JButton nextQuote) { |
| 85 | + this.nextQuote = nextQuote; |
| 86 | + } |
| 87 | + public JButton getNextQuote() { |
| 88 | + return nextQuote; |
| 89 | + } |
| 90 | + public void setFrame(JFrame frame) { |
| 91 | + this.frame = frame; |
| 92 | + } |
| 93 | + public static void setQuotes(ArrayList<Quote> quotes) { |
| 94 | + quotesList = quotes; |
| 95 | + } |
| 96 | + public ArrayList<Quote> getQuotes(){ |
| 97 | + return quotesList; |
| 98 | + } |
| 99 | + public void setTextLabel(JLabel textLabel) { |
| 100 | + this.textLabel = textLabel; |
| 101 | + } |
| 102 | + public JLabel getTextLabel() { |
| 103 | + return textLabel; |
| 104 | + } |
| 105 | + |
| 106 | + |
| 107 | +} |
0 commit comments