#java swing
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Sure, I can help you with that. Here is an example of a Java Swing application using at least 13 Java Swing components:
import javax.swing.*;
import java.awt.*;
public class SwingApplication extends JFrame {
public SwingApplication() {
setTitle("Java Swing Application");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 3));
JLabel label1 = new JLabel("Label 1");
JTextField textField = new JTextField();
JButton button1 = new JButton("Button 1");
JLabel label2 = new JLabel("Label 2");
JCheckBox checkBox = new JCheckBox("Check Box");
JLabel label3 = new JLabel("Label 3");
JRadioButton radioButton1 = new JRadioButton("Radio Button 1");
JRadioButton radioButton2 = new JRadioButton("Radio Button 2");
JLabel label4 = new JLabel("Label 4");
JComboBox<String> comboBox = new JComboBox<>(new String[]{"Option 1", "Option 2", "Option 3"});
JLabel label5 = new JLabel("Label 5");
JList<String> list = new JList<>(new String[]{"Item 1", "Item 2", "Item 3"});
JLabel label6 = new JLabel("Label 6");
JTextArea textArea = new JTextArea();
```
panel.add(label1);
panel.add(textField);
panel.add(button1);
panel.add(label2);
panel.add(checkBox);
panel.add(label3);
panel.add(radioButton1);
panel.add(radioButton2);
panel.add(label4);
panel.add(comboBox);
panel.add(label5);
panel.add(list);
panel.add(label6);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
getContentPane().add(panel, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new SwingApplication();
});
}
}
This code creates a simple Java Swing application with various components such as labels, text fields, buttons, check boxes, radio buttons, combo boxes, lists, and text areas. You can customize the layout and appearance of these components as needed. Let me know if you need any further assistance!
which part are you stuck on?
@warm harbor
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure ๐
A for-loop adding 13 labels should do it...
What do you have so far?
The Java MOOC will teach Java but (later in the course) teaches GUIs with JavaFX.
There are a few 'getting started with swing' tutorials that might help you get going (assuming you already know a decent bit of Java)
@warm harbor if u want us to write all the code for u then we dont do that here