I'm making a simple weather app using IntelliJ and built in form designer. I have made and designed a form and edited the bound class file accordingly. When I actually run the code, the form I designed does now show up at all, in fact just the last line (maxtemp) is the only value that shows up on an empty white screen.
P.S I am using Gradle to build, I have also set the GUI designer to use Java source code instead of byte code (since Gradle does not support the byte code)
import org.json.JSONException;
import org.json.JSONObject;
import javax.swing.*;
import java.awt.*;
public class Frame extends JFrame {
// Get the API
private API api = new API();
// Form elements
public JPanel mainPanel;
public JLabel text;
public JLabel category;
public JLabel mintemp;
public JLabel maxtemp;
public JLabel link;
public Frame() throws Exception, JSONException {
initFrame();
}
public void initFrame() throws Exception, JSONException {
// Get API response
JSONObject wjson = api.connection();
// Filter response and get data
String[] data = api.respFilter(wjson);
// Swing components
mainPanel = new JPanel(new BorderLayout());
text = new JLabel();
category = new JLabel();
mintemp = new JLabel();
maxtemp = new JLabel();
link = new JLabel();
// Add to the frame
add(mainPanel);
add(text);
add(category);
add(mintemp);
add(maxtemp);
text.setText(data[0]);
category.setText(data[1]);
mintemp.setText(data[3]);
maxtemp.setText(data[4]);
}
public static void main(String[] args) throws Exception, JSONException {
JFrame app = new Frame();
app.setTitle("Java-WeatherApp");;
app.setSize(900, 600);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setLocationRelativeTo(null);
app.setVisible(true);
}
}
I'm pretty new to Java and very new to the form builder on IntelliJ. Unfortunately I could not find any good tutorials on the form builder. Any help is appreciated!
JFrame
, by default, uses aBorderLayout
. Next, drop the form editor and make the time to do some of your UI code by hand, it will allow you to better understand these problems and fix them