When I run my code setLayout is not working with JPanel
I keep getting the errors that:
The method setLayout(LayoutManager) in the type JFrame is not applicable for the arguments (GridLayout)
The constructor GridLayout(int, int) is undefined
When I look as to why it says that:
The method setLayout(LayoutManager)
in the type Container is not applicable for the arguments (GridLayout
)
and
Is anyone familiar with Swing?
Code:
public class YoutubeSwing extends MainSceneSwing{
public static JFrame frameTwo = new JFrame();
public static JPanel topPanel = new JPanel();
public static JPanel secondPanel = new JPanel();
public static String songTitle;
public static String artistName;
public static void main(String[] args) {
runSimulation();
}
public static void runSimulation() {
setUp();
}
public static void topPanel() {
topPanel.setLayout(new FlowLayout());
JLabel title = new JLabel("Not-ify", JLabel.CENTER);
title.setForeground(Color.BLUE);
title.setFont(Title);
topPanel.add(title);
}
public static void secondPanel() {
secondPanel.setLayout(new FlowLayout());
JLabel subtitle = new JLabel("Youtube Music Player", JLabel.CENTER);
subtitle.setFont(Text);
secondPanel.add(subtitle);
JLabel disclaimer = new JLabel("We may place adds before your music so that we can generate some revenue. Please note that we are starving students.", JLabel.CENTER);
disclaimer.setFont(ButtonText);
secondPanel.add(disclaimer);
}
public static void setUp() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(WIDTH, HEIGHT));
frame.setTitle("Not-ify");
frame.setLayout(new GridLayout(4,1));
topPanel();
secondPanel();
JPanel thirdPanel = new JPanel();
secondPanel.setLayout(new GridLayout(4, 1));
thirdPanel.setLayout(new GridLayout(4,1));
JTextArea artist = new JTextArea(
"Please enter the artist of your choice: ");
JTextArea artistAnswer = new JTextArea(
"Drake");//**TODO Uncheck */
JTextArea song = new JTextArea(
"Please enter the song of your choice: ");
JTextArea songAnswer = new JTextArea(
"One Dance");//**TODO Uncheck */
artist.setEditable(false);
artistAnswer.setEditable(true);
song.setEditable(false);
songAnswer.setEditable(true);
thirdPanel.add(artist);
thirdPanel.add(artistAnswer);
thirdPanel.add(song);
thirdPanel.add(songAnswer);
JButton start = new JButton("Start");
ActionListener startListener = new YoutubePlayerButtonListener(start,artistAnswer,songAnswer);
start.setForeground(Color.GREEN);
start.setFont(Subtitle);
start.addActionListener(startListener);
frame.add(topPanel);
frame.add(secondPanel);
frame.add(thirdPanel);
frame.add(start);
frame.pack();
frame.setVisible(true);
}
public static void start(String artistName, String song, String lyrics, String url, String youtubeLink) {
// Set up screen
frameTwo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameTwo.setSize(new Dimension(WIDTH, HEIGHT));
frameTwo.setTitle("Not-ify");
frameTwo.setLayout(new BorderLayout());
JPanel leftPanel = new JPanel();
leftPanel.setLayout(new GridLayout(2,1));
JLabel nowPlaying = new JLabel("Currently Playing: " + song + " by " + artistName);
nowPlaying.setAlignmentX(JLabel.CENTER_ALIGNMENT);
leftPanel.add(nowPlaying);
JTextArea scrollLyrics = new JTextArea(lyrics);
scrollLyrics.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
scrollLyrics.setEditable(false);
JScrollPane scroll = new JScrollPane(scrollLyrics);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.getViewport().setView(scrollLyrics);
leftPanel.add(scroll);
JFXPanel youtubePlayer = new JFXPanel();
Platform.runLater(new Runnable() {
@Override
public void run() {
//Youtube panel
WebEngine engine;
WebView view = new WebView();
engine = view.getEngine();
engine.load(youtubeLink);
youtubePlayer.setScene(new Scene(view));
}});
frameTwo.add(leftPanel, BorderLayout.CENTER);
frameTwo.add(youtubePlayer, BorderLayout.SOUTH);
frameTwo.pack();
youtubePlayer.setVisible(false);
frameTwo.setVisible(true);
}
}
Thanks in advance for taking a look. It was working one second and then boom.
from Recent Questions - Stack Overflow https://ift.tt/3aQDkgW
https://ift.tt/eA8V8J
Comments
Post a Comment