Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Fetches weather data using a REST API and displays results in Codename One.
import com.codename1.ui.*;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.*;
public class WeatherApp extends Form {
public WeatherApp() {
setTitle("Weather App");
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextField city = new TextField("", "Enter City");
Button fetch = new Button("Fetch");
Label result = new Label();
fetch.addActionListener(e -> {
ConnectionRequest req = new ConnectionRequest();
req.setUrl("https://api.weatherapi.com/v1/current.json?key=demo&q=" + city.getText());
req.addResponseListener(res -> {
String data = new String(req.getResponseData());
result.setText(data.substring(0, Math.min(100, data.length())) + "...");
revalidate();
});
NetworkManager.getInstance().addToQueue(req);
});
addAll(city, fetch, result);
}
}Codename One is a cross-platform mobile development framework that allows developers to build native mobile apps for iOS, Android, Windows, macOS, and web using Java or Kotlin. It provides a single codebase with a rich set of UI components and native device access.
Origin & Creator
Created by Shai Almog and the Codename One team in 2012, Codename One was designed to simplify mobile app development across platforms using Java.
Industrial Note
Best suited for teams with strong Java expertise who want to write once and deploy anywhere without managing multiple platform-specific projects.