So i just started with eclipse and java script and i am also a new coder. I started of wtih this random name picker project. And the code is written like this:
public static void gods() {
System.out.println("You have to play this God:");
String[] gods =
{"Agni",
"Ah Muzen Cab",
"Ah Puch",
"Amaterasu",
"Anhur",
"Anubis",
"Ao Kuang",
"Aphrodite",
"Apollo",
"Arachne",
"Ares",
"Artemis",
"Athena",
"Awilix",
"Bacchus",
"Bakasura",
"Bastet",
"Bellona",
"Cabrakan",
"Chaac",
"Change",
"Chiron",
"Chronos",
"Cupid",
"Fenrir",
"Geb",
"Guan Yu",
"Hades",
"He Bo",
"Hel",
"Hercules",
"Hou Yi",
"Hun Batz",
"Isis",
"Janus",
"Kali",
"Khepri",
"Kukulkan",
"Kumbhakarna",
"Loki",
"Medusa",
"Mercury",
"Ne Zha",
"Neith",
"Nemesis",
"Nox",
"Nu Wa",
"Odin",
"Osiris",
"Poseidon",
"Ra",
"Rama",
"Ratatoskr",
"Ravana",
"Scylla",
"Serqet",
"Sobek",
"Sol",
"Sun Wukong",
"Sylvanus",
"Thanatos",
"Thor",
"Tyr",
"Ullr",
"Vamana",
"Vulcan",
"Xbalanque",
"Xing Tian",
"Ymir",
"Zeus",
"Zhong Kui"};
List<String> names = Arrays.asList(gods);
int index = new Random().nextInt(names.size());
String name = names.get(index);
System.out.print(name + " ");
}
public static void roles() {
String[] roles = {" Solo", " Jungle", " Mid", " ADC", " Support"};
List<String> names = Arrays.asList(roles);
int index = new Random().nextInt(names.size());
String name = names.get(index);
System.out.print(name + " ");}
public void Randomize() {
System.out.println("Here you have your god:");
gods();
System.out.println("Here you have your role:");
roles();}
But i want to import or set in this code inside my windowbuilder plugin. I have tried inserting it inside a JButton as an "actionPerformed" but when i launched the program and clicked the button it opened up the console in eclipse when i want it to open inside the program.
This is my windowbuilder code:
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Plswork window = new Plswork();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Plswork() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.getContentPane().setFont(new Font("Comic Sans MS", Font.PLAIN, 18));
frame.getContentPane().setBackground(Color.MAGENTA);
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
txtAronErDu = new JTextField();
txtAronErDu.setFont(new Font("SWTOR Trajan", Font.PLAIN, 22));
txtAronErDu.setText("Aron er du homofil?");
txtAronErDu.setBounds(0, 0, 434, 39);
frame.getContentPane().add(txtAronErDu);
txtAronErDu.setColumns(10);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(199, 118, 89, 23);
frame.getContentPane().add(btnNewButton);
}
public void actionPerformed(ActionEvent e) {
}
}
PS: This is how it looks when i imoprt it:
public class Plswork {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Plswork window = new Plswork();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.getContentPane().setFont(new Font("Comic Sans MS", Font.PLAIN, 18));
frame.getContentPane().setBackground(Color.MAGENTA);
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Sebbe");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("You have to play this God:");
String[] gods =
{"Agni",
"Ah Muzen Cab",
"Ah Puch",
"Amaterasu",
"Anhur",
"Anubis",
"Ao Kuang",
"Aphrodite",
"Apollo",
"Arachne",
"Ares",
"Artemis",
"Athena",
"Awilix",
"Bacchus",
"Bakasura",
"Bastet",
"Bellona",
"Cabrakan",
"Chaac",
"Change",
"Chiron",
"Chronos",
"Cupid",
"Fenrir",
"Geb",
"Guan Yu",
"Hades",
"He Bo",
"Hel",
"Hercules",
"Hou Yi",
"Hun Batz",
"Isis",
"Janus",
"Kali",
"Khepri",
"Kukulkan",
"Kumbhakarna",
"Loki",
"Medusa",
"Mercury",
"Ne Zha",
"Neith",
"Nemesis",
"Nox",
"Nu Wa",
"Odin",
"Osiris",
"Poseidon",
"Ra",
"Rama",
"Ratatoskr",
"Ravana",
"Scylla",
"Serqet",
"Sobek",
"Sol",
"Sun Wukong",
"Sylvanus",
"Thanatos",
"Thor",
"Tyr",
"Ullr",
"Vamana",
"Vulcan",
"Xbalanque",
"Xing Tian",
"Ymir",
"Zeus",
"Zhong Kui"};
List<String> names = Arrays.asList(gods);
int index = new Random().nextInt(names.size());
String name = names.get(index);
System.out.print(name + " ");
}
});
btnNewButton.setBounds(167, 117, 89, 23);
frame.getContentPane().add(btnNewButton);
}
public void actionPerformed(ActionEvent e) {
}
}
Related
I have been trying to create a flight arrivals map program using windowbuilder however I have been stuck on displaying in the incoming flights for each airport
For context this map[ should display incoming flights when you hover your mouse on the letters(i.e hovering on YYZ will display incoming flight arrivals for Toronto airport)
I have an set of ArrayLists from a java file. Lets call it Aeroports.java which scans a csv file and scans it adding a line into a certain arraylist depending on its airport code(e.g YYZFlights)
The CSV file is in the format
DateOfFlight[0],DepartureTime1,ArrivalTime2,FlightDuration[3]
I have posted the full code below. I had to change the format of the dat so it could be read
Below is the program which stores the setters(procedures) and getters(functions) for each object
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Date;
public class Flights {
private String flightNo;
private String departureCity;
private String departureAirport;
private String ArrivalAirport;
private int delayedTime;
private LocalTime newArrivalTime;
private LocalTime ArrivalTime;
private LocalTime departureTime;
private LocalDate FlightDate;
public void setFlightNo(String flightNo)///sets the flightNo for each object
{
this.flightNo = flightNo;
}
public String getFlightNo()
{
return flightNo;
}
public void setdepartureCity(String departureCity)///sets the departure city for each object
{
this.departureCity = departureCity;
}
public String getdepartureCity()
{
return departureCity;
}
public void setdepartureAirport(String departureAirport)///sets the departure airport for each object
{
this.departureAirport = departureAirport;
}
public String getdepartureAirport()
{
return departureAirport;
}
public void setdelayedTime(int delayedTime)
{
this.delayedTime = delayedTime;
}
public int getdelayedTime()
{
return delayedTime;
}
public void setnewArrivalTime(LocalTime newArrivalTime)
{
this.newArrivalTime = newArrivalTime;
}
public LocalTime getnewArrivalTime()
{
return newArrivalTime;
}
public void setArrivalTime(LocalTime newArrivalTime)
{
this.ArrivalTime = newArrivalTime;
}
public LocalTime getArrivalTime()
{
return ArrivalTime;
}
public void setdepartureTime(LocalTime departureTime)
{
this.departureTime = departureTime;
}
public LocalTime getdepartureTime()
{
return departureTime;
}
public void setArrivalAirport(String ArrivalAirport)
{
this.ArrivalAirport = ArrivalAirport;
}
public String getArrivalAirport()
{
return ArrivalAirport;
}
public void setFlightDate( LocalDate FlightDate)
{
this.FlightDate = FlightDate;
}
public LocalDate getFlightDate( )
{
return FlightDate;
}
}
Listed below is the main program where delayed flights are calculated for each object and stores the ArrayLists that I intend to use in the future
import java.util.ArrayList;
import java.util.Date;
import java.time.format.DateTimeFormatter;
import java.io.*;
import java.util.Scanner;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;
import java.time.*;
public class BCLAirport {
static ArrayList<Flights> allFlights = new ArrayList<Flights>();
static ArrayList<Flights> alldelayedFlights = new ArrayList<Flights>();
static ArrayList<Flights> BCLFlights = new ArrayList<Flights>();///Array list for Airport with code BCL the ones for the others are listed below
static ArrayList<Flights> SYDFlights = new ArrayList<Flights>();
static ArrayList<Flights> DXBFlights = new ArrayList<Flights>();
static ArrayList<Flights> DELFlights = new ArrayList<Flights>();
static ArrayList<Flights> BKKFlights = new ArrayList<Flights>();
static ArrayList<Flights> DUBFlights = new ArrayList<Flights>();
static ArrayList<Flights> CDGFlights = new ArrayList<Flights>();
static ArrayList<Flights> GRUFlights = new ArrayList<Flights>();
static ArrayList<Flights> YYZFlights = new ArrayList<Flights>();
static ArrayList<Flights> JFKFlights = new ArrayList<Flights>();
static ArrayList<Flights> MEXFlights = new ArrayList<Flights>();
static ArrayList<Flights> ARNFlights = new ArrayList<Flights>();
static ArrayList<Flights> CAIFlights = new ArrayList<Flights>();
static ArrayList<Flights> LOSFlights = new ArrayList<Flights>();
static ArrayList<Flights> AMSFlights = new ArrayList<Flights>();
static ArrayList<Flights> LVSFlights = new ArrayList<Flights>();
static ArrayList<Flights> DFWFlights = new ArrayList<Flights>();
static ArrayList<Flights> JNBFlights = new ArrayList<Flights>();
static ArrayList<Flights> HNDFlights = new ArrayList<Flights>();
static ArrayList<Flights> SVOFlights = new ArrayList<Flights>();
static ArrayList<Flights> LISFlights = new ArrayList<Flights>();
static ArrayList<Flights> MADFlights = new ArrayList<Flights>();
static ArrayList<Flights> RAKFlights = new ArrayList<Flights>();
static ArrayList<Flights> ATHFlights = new ArrayList<Flights>();
static ArrayList<Flights> FCOFlights = new ArrayList<Flights>();
public static void mainrun() throws ParseException ///
{
try
{
File myObj = new File("C:/Flights.csv"//this leads to flight csv file imagine this in a format); //Scans for the csv file
Scanner myReader = new Scanner(myObj);///gets input of csv file
while (myReader.hasNextLine())
{
String[] data = myReader.nextLine().split(",");///splits the line by the commas
Flights Flights = new Flights();//creayes new object
Flights.setdepartureAirport(data[6]);///sets the departure airport
Flights.setdepartureCity(data[7]);/// sets the departure city
Flights.setFlightNo(data[10]);//sets the flight number
Flights.setdelayedTime(Integer.parseInt(data[5]));// sets the delayed time
Flights.setdepartureTime(LocalTime.parse(data[1]));///sets the departure Time
Flights.setArrivalAirport(data[8]);
Flights.setArrivalTime(LocalTime.parse(data[2]));
String[] dating = data[0].split("/");
String newdating = dating[2]+"-"+dating[1]+"-"+dating[0];
data[0]=newdating;//writes the date in the new format
LocalDate todaysDate = LocalDate.now();
Flights.setFlightDate(LocalDate.parse(data[0]));
int delayTime = Integer.parseInt(data[5]);/// integer for the delayed time in minutes
if (LocalDate.parse(newdating).equals(todaysDate)) {
System.out.println("yes");
if (Flights.getArrivalAirport() == "BCL") {///Array lists for each airport
BCLFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "SYD") {
SYDFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "DXB") {
DXBFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "DEL") {
DELFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "BKK") {
BKKFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "DUB") {
DUBFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "CDG") {
CDGFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "GRU") {
GRUFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "YYZ") {
YYZFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "JFK") {
JFKFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "MEX") {
MEXFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "ARN") {
ARNFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "CAI") {
CAIFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "LOS") {
LOSFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "AMS") {
AMSFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "LVS") {
LVSFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "DFW") {
DFWFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "JNB") {
JNBFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "HND") {
HNDFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "SVO") {
SVOFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "LIS") {
LISFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "MAD") {
MADFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "RAK") {
RAKFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "ATH") {
ATHFlights.add(Flights);
} else if (Flights.getArrivalAirport() == "FCO") {
FCOFlights.add(Flights);
}
if (delayTime >= 30) {
LocalTime oldTime = Flights.getArrivalTime();
// Flights.setArrivalTime(oldTime);formatter.format(today)
LocalTime newTime = oldTime.plusMinutes(delayTime);/// adds the delayed time
Flights.setnewArrivalTime(newTime);
alldelayedFlights.add(Flights);
}
}
//........
//if flightdate .equals date;
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date today = new Date();
//System.out.println(formatter.format(today));
// "2022-03-03"*/
// Date todayWithZeroTime = formatter.parse(formatter.format(today));
}
myReader.close();// closes the reader
//for(int i = 0; i < allFlights.size();i++)
///{
///System.out.println(allFlights.get(i).getdepartureCity() + " " +allFlights.get(i).getdepartureAirport() + " " + allFlights.get(i).getFlightNo() + " delayed by " + allFlights.get(i).getdelayedTime() + " minutes") ;
///}
for(int i = 0; i < alldelayedFlights.size();i++)///for the length of the array list delayed flights
{
//System.out.println(alldelayedFlights.get(i).getdepartureTime() + " " +alldelayedFlights.get(i).getdepartureAirport() + " " + alldelayedFlights.get(i).getArrivalAirport() + " " + alldelayedFlights.get(i).getArrivalTime() + " " + alldelayedFlights.get(i).getdelayedTime() + " " + alldelayedFlights.get(i).getnewArrivalTime() + " " + alldelayedFlights.get(i).getFlightDate()) ;
}
}
catch (FileNotFoundException e)
{
System.out.println("File cannot be found");
e.printStackTrace();
}
}
}
In another GUI java program I have used the pop up method to show a window depending on which airport I click on.
lblNewLabel_11 = new JLabel("HND");
lblNewLabel_11.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_11.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_11.setBounds(817, 277, 27, 13);
contentPane.add(lblNewLabel_11);
lblNewLabel_12 = new JLabel("SYD");
lblNewLabel_12.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_12.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_12.setBounds(855, 503, 45, 13);
contentPane.add(lblNewLabel_12);
lblNewLabel_13 = new JLabel("JNB");
lblNewLabel_13.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
Below is the UI file which uses window builder to build a UI
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextPane;
import javax.swing.JLabel;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JPasswordField;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import com.toedter.calendar.JCalendar;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class MainFrame extends JFrame {
private JPanel contentPane;
private JPasswordField passwordField;
private JLabel lblNewLabel;
private JLabel lblNewLabel_1;
private JLabel lblMad;
private JLabel lblNewLabel_2;
private JLabel lblNewLabel_3;
private JLabel lblNewLabel_4;
private JLabel lblNewLabel_5;
private JLabel lblNewLabel_6;
private JLabel lblNewLabel_7;
private JLabel lblNewLabel_8;
private JLabel lblNewLabel_9;
private JLabel lblNewLabel_10;
private JLabel lblNewLabel_11;
private JLabel lblNewLabel_12;
private JLabel lblNewLabel_13;
private JLabel lblNewLabel_14;
private JLabel lblNewLabel_15;
private JLabel lblNewLabel_16;
private JLabel lblNewLabel_17;
private JLabel lblNewLabel_18;
private JLabel lblNewLabel_19;
private JLabel lblNewLabel_20;
private JLabel lblNewLabel_21;
private JLabel lblNewLabel_22;
private JLabel lblNewLabel_23;
private JLabel lblNewLabel_24;
private JLabel lblNewLabel_25;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BCLAirport.mainrun();
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1351, 770);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
lblNewLabel_18 = new JLabel("DFW");
lblNewLabel_18.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_18.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_18.setBounds(105, 290, 27, 13);
contentPane.add(lblNewLabel_18);
lblNewLabel_16 = new JLabel("LVS");
lblNewLabel_16.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_16.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_16.setBounds(52, 267, 55, 13);
contentPane.add(lblNewLabel_16);
lblNewLabel_4 = new JLabel("YYZ\r\n");
lblNewLabel_4.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_4.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_4.setBounds(187, 231, 33, 13);
contentPane.add(lblNewLabel_4);
lblNewLabel_2 = new JLabel("DUB");
lblNewLabel_2.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_2.setBounds(388, 216, 27, 13);
contentPane.add(lblNewLabel_2);
lblNewLabel_1 = new JLabel("BCL");
lblNewLabel_1.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_1.setBounds(420, 210, 27, 24);
contentPane.add(lblNewLabel_1);
lblNewLabel_3 = new JLabel("JFK");
lblNewLabel_3.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_3.setBounds(193, 267, 27, 13);
contentPane.add(lblNewLabel_3);
lblMad = new JLabel("MAD");
lblMad.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblMad.setFont(new Font("Tahoma", Font.BOLD, 10));
lblMad.setBounds(414, 267, 33, 13);
contentPane.add(lblMad);
lblNewLabel_5 = new JLabel("LIS");
lblNewLabel_5.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_5.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_5.setBounds(383, 267, 21, 13);
contentPane.add(lblNewLabel_5);
lblNewLabel_6 = new JLabel("CAI");
lblNewLabel_6.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_6.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_6.setBounds(502, 309, 27, 13);
contentPane.add(lblNewLabel_6);
lblNewLabel_7 = new JLabel("DXB");
lblNewLabel_7.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_7.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_7.setBounds(569, 321, 27, 13);
contentPane.add(lblNewLabel_7);
lblNewLabel_8 = new JLabel("DEL");
lblNewLabel_8.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_8.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_8.setBounds(647, 309, 21, 13);
contentPane.add(lblNewLabel_8);
lblNewLabel_9 = new JLabel("BKK");
lblNewLabel_9.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_9.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_9.setBounds(727, 343, 27, 13);
contentPane.add(lblNewLabel_9);
lblNewLabel_10 = new JLabel("HKG");
lblNewLabel_10.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_10.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_10.setBounds(756, 309, 27, 13);
contentPane.add(lblNewLabel_10);
lblNewLabel_11 = new JLabel("HND");
lblNewLabel_11.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_11.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_11.setBounds(817, 277, 27, 13);
contentPane.add(lblNewLabel_11);
lblNewLabel_12 = new JLabel("SYD");
lblNewLabel_12.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_12.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_12.setBounds(855, 503, 45, 13);
contentPane.add(lblNewLabel_12);
lblNewLabel_13 = new JLabel("JNB");
lblNewLabel_13.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_13.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_13.setBounds(484, 503, 21, 13);
contentPane.add(lblNewLabel_13);
lblNewLabel_14 = new JLabel("LOS");
lblNewLabel_14.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_14.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_14.setBounds(433, 371, 21, 13);
contentPane.add(lblNewLabel_14);
lblNewLabel_15 = new JLabel("RAK");
lblNewLabel_15.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_15.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_15.setBounds(381, 290, 34, 13);
contentPane.add(lblNewLabel_15);
lblNewLabel_17 = new JLabel("GRU");
lblNewLabel_17.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_17.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_17.setBounds(264, 480, 27, 13);
contentPane.add(lblNewLabel_17);
lblNewLabel_19 = new JLabel("MEX");
lblNewLabel_19.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_19.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_19.setBounds(93, 321, 27, 13);
contentPane.add(lblNewLabel_19);
lblNewLabel_20 = new JLabel("ATH");
lblNewLabel_20.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_20.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_20.setBounds(478, 267, 27, 13);
contentPane.add(lblNewLabel_20);
lblNewLabel_21 = new JLabel("CDG");
lblNewLabel_21.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_21.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_21.setBounds(420, 244, 27, 13);
contentPane.add(lblNewLabel_21);
lblNewLabel_22 = new JLabel("ARN");
lblNewLabel_22.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_22.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_22.setBounds(453, 186, 27, 13);
contentPane.add(lblNewLabel_22);
lblNewLabel_23 = new JLabel("AMS");
lblNewLabel_23.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_23.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_23.setBounds(453, 216, 27, 13);
contentPane.add(lblNewLabel_23);
lblNewLabel_24 = new JLabel("SVO");
lblNewLabel_24.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_24.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_24.setBounds(520, 216, 45, 13);
contentPane.add(lblNewLabel_24);
lblNewLabel_25 = new JLabel("FCO");
lblNewLabel_25.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
lblNewLabel_25.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel_25.setBounds(453, 255, 27, 13);
contentPane.add(lblNewLabel_25);
lblNewLabel = new JLabel("Map(don't delete)");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 10));
lblNewLabel.setBounds(0, 130, 944, 469);
lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Student\\Pictures\\GUI\\map.png"));
contentPane.add(lblNewLabel);
JTextArea textArea = new JTextArea();
textArea.setBounds(970, 133, 334, 571);
contentPane.add(textArea);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setBounds(970, 133, 334, 571);
contentPane.add(scroll);
JButton btnNewButton = new JButton("LVS");
lblMad.addMouseListener(new MouseAdapter() {
Popup frame = new Popup();
public void mouseEntered(MouseEvent e) {
frame.setVisible(true);
}
public void mouseExited(MouseEvent e) {
frame.setVisible(false);
}
});
btnNewButton.setBounds(52, 263, 45, 21);
contentPane.add(btnNewButton);
JLabel lblNewLabel_26 = new JLabel("Delayed Flights");
lblNewLabel_26.setFont(new Font("Tahoma", Font.BOLD, 21));
lblNewLabel_26.setBounds(1034, 72, 189, 51);
contentPane.add(lblNewLabel_26);
for (Flights f:BCLAirport.alldelayedFlights )
{
textArea.append(f.getdepartureTime() + " " +f.getdepartureAirport() + " " + f.getArrivalAirport() + " " + f.getArrivalTime() + " " + f.getdelayedTime() + " " + f.getnewArrivalTime() + " " + f.getFlightDate() + "\n" );//prints the results and goes to a new line
}
}
}
The main issue I have having is working out how to implement a way to show the incoming flightArrivals for each airport depending on which aiport I click for a reference see the picture for how the airport UI looksHere's UI normally
When I hover on the name of an airport at the moment blank window pops up but I want it to show the incoming arrivals for the day. I have been able to show delayedFlights but have been unable to show the specific arraylists for each airport which I want to show in the format
ArrivalTime, Departure City, Departure Airport, FlightNo
It should look like this when you hover on a airport nameHow it should ideally look like
If someone could help that would be great becaus I'm quite stuck
What exactly is your issue? Is it that you only see delayed flights but not all flights? You have static ArrayList<Flights> allFlights = new ArrayList<Flights>(); but as far as I see you never add a flight to it. You only add flights to the other lists.
Unrelated to your main issue, but some general observations:
Consider renaming Flights to Flight This class is a single flight, not a list of flights right?
You have an ArrayList<Flight> for every airport. This seems really difficult to work with. Maybe there is a different data structure that better fits your needs. Maybe Map<Airport, List<Flight>> flightsByAirport
It looks like each airport is it's own class? BCLAirport Maybe there is a different way to handle that.
I have a project that uses JFreeChart.
The chart that I am using is displaying correctly and works fine with the current code.
My problem is that I can only position the graph to the east, south, west, center or north of my JPanel.
My desire is to move this chart to any position inside my JPanel.
This is the short code snippet where I add my graph to the panSimulator JPanel. The problematic code is at the bottom of the ConfigurationFrame class:
public class ConfigurationFrame extends JFrame {
private KettlerBikeConnector bike1 = null;
private static final long serialVersionUID = 1L;
CrosshairDemo chd = new CrosshairDemo();
private JPanel panSimulator;
private PanelBikeSimulator panBSim;
private Timer timerBike;
private TimerListener listener;
private final int UPDATE_MS = 1000; // updates every second
private JTabbedPane tabPane;
private JPanel panConfiguration;
private JPanel panGame;
private JComboBox<String> cbxPort;
private JTextPane lblStatus;
// to have access to the textfield
public static JTextField txtEnergy;
public static JTextField txtDistance;
public static JTextField txtHeartRate;
public static JTextField txtTime;
public File path = null;
public int key = -1;
boolean run = true;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ConfigurationFrame frame = new ConfigurationFrame();
frame.setVisible(true);
// frame.pack(); // give a suitable size to window automatically
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* #throws IOException
* #throws SAXException
* #throws ParserConfigurationException
*/
public ConfigurationFrame() throws ParserConfigurationException, SAXException, IOException {
setResizable(false);
setMinimumSize(new Dimension(1900, 1000));
setTitle("Bike Simulation ... I need a name ...");
setLocationRelativeTo(null);
addWindowListener(new WindowAdapter() {
#Override
public void windowClosed(WindowEvent arg0) {
try {
timerBike.stop();
bike1.close();
} catch (Exception e) {
log(e.getMessage());
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
getContentPane().setLayout(null);
// Panel
tabPane = new JTabbedPane(JTabbedPane.TOP);
tabPane.setFont(new Font("Tahoma", Font.PLAIN, 24));
tabPane.setBounds(0, 0, 1892, 994);
getContentPane().add(tabPane);
// Configuration-Panel
panConfiguration = new JPanel();
tabPane.addTab("Configuration", null, panConfiguration, null);
panConfiguration.setLayout(null);
// ComboBox for Kettler
cbxPort = new JComboBox<String>();
cbxPort.setFont(new Font("Tahoma", Font.PLAIN, 24));
cbxPort.setBounds(734, 5, 247, 49);
panConfiguration.add(cbxPort);
// Button-Connection
JButton btnConnect = new JButton("Connect");
btnConnect.setFont(new Font("Tahoma", Font.PLAIN, 24));
btnConnect.setBounds(157, 7, 137, 49);
btnConnect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
bike1 = new KettlerBikeConnector();
bike1.connect(cbxPort.getSelectedItem().toString(), new KettlerBikeListener() {
#Override
public void bikeAck() {
switch (listener.state) {
case hello:
listener.state = State.connected;
break;
case reset:
listener.state = State.hello;
break;
case connected:
log("connection successful");
break;
case notConnected:
log("not connected");
break;
}
}
#Override
public void bikeData(DataRecord data) {
//Sending the Ergometer velcoity every 1000ms to the
panBSim.setErgometerVelocity(data.getSpeed() / 10);
panBSim.setErgometerRPM(data.getPedalRpm());
panBSim.setTrueDataHere(true);
double power = panBSim.getTraveledDistance();
chd.setPower(power);
//getPower und dann set hier die Ergometer widerstand
try {
bike1.sendSetPower(panBSim.getErgometerPower());
} catch (IOException ignored) {
System.out.println("ignored");
}
}
#Override
public void bikeDestPowerChanged(int power) {
log("dest power: " + power);
}
#Override
public void bikeError() {
log("error1");
}
});
} catch (Exception e) {
log(e.getMessage());
}
}
});
panConfiguration.add(btnConnect);
// Button-Start
JButton btnStart = new JButton("Start");
btnStart.setFont(new Font("Tahoma", Font.PLAIN, 24));
btnStart.setBounds(304, 7, 137, 49);
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
listener = new TimerListener(bike1);
timerBike = new Timer(UPDATE_MS, listener);
timerBike.start();
tabPane.setSelectedComponent(panSimulator); // switch to GamePanel
panBSim.startSimulate();
} catch (Exception e) {
log(e.getMessage());
}
}
});
panConfiguration.add(btnStart);
// Button-Scan
JButton btnScan = new JButton("Scan");
btnScan.setFont(new Font("Tahoma", Font.PLAIN, 24));
btnScan.setBounds(10, 7, 137, 49);
btnScan.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers(); // list of named
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
cbxPort.addItem(portId.getName());
if (portId.isCurrentlyOwned()) {
log("Port " + portId.getName() + " is already open");
}
}
}
}
});
panConfiguration.add(btnScan);
// Status displays information regarding connection
lblStatus = new JTextPane();
lblStatus.setText(
"Anweisung:\r\n\t1) W\u00E4hle ein Lebensmittel aus der Food-Item Combobox aus\r\n\t2) Dr\u00FCcke den Scan-Button und w\u00E4hle den Port aus der Port Combobox aus\r\n\t3) Dr\u00FCcke den Connect-Button, um die Ger\u00E4te zu verbinden\r\n\t4) Dr\u00FCcke den Start-Button, um die Anwendung zu starten\r\n\t5) Warte auf das akustische Signal des Ergometer\r\n\t6) Beginne zu treten");
lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 24));
lblStatus.setBounds(10, 125, 971, 229);
lblStatus.setDisabledTextColor(Color.BLACK);
lblStatus.setSelectionColor(new Color(51, 153, 255));
panConfiguration.add(lblStatus);
// FH Logo
JLabel lblLogo = new JLabel("");
lblLogo.setBounds(10, 365, 971, 430);
try {
File in = new File("FHLogo.png");
Image logo = ImageIO.read(in);
Image scaledLogo = logo.getScaledInstance(lblLogo.getWidth(), lblLogo.getHeight(), Image.SCALE_SMOOTH);
ImageIcon iconLogo = new ImageIcon(scaledLogo);
lblLogo.setIcon(iconLogo);
} catch (IOException e2) {
e2.printStackTrace();
}
panConfiguration.add(lblLogo);
// Labels
JLabel lblPort = new JLabel("Port:");
lblPort.setFont(new Font("Tahoma", Font.PLAIN, 24));
lblPort.setBounds(600, 5, 124, 49);
panConfiguration.add(lblPort);
//-----------------------------------------------------------------------------XXX
//Tab Bike Simulator
BorderLayout bdl = new BorderLayout();
panSimulator = new JPanel();
tabPane.addTab("Bike Simulator", null, panSimulator, null);
panSimulator.setLayout(bdl);
//Panel Bike Simulator
//panBSim = new PanelBikeSimulator();
//panBSim.setBorder(BorderFactory.createLineBorder(Color.black));
panSimulator.add(chd.getContentPane(), bdl.NORTH);
}
/**
* To log information
*
* #param str String that is shown
*/
private void log(String str) {
lblStatus.setText(lblStatus.getText() + str + "\n");
}
}
And this class belongs to my chart that I want to move to any location in my JPanel.
public class CrosshairDemo extends JFrame {
private static double POWER = 0.0;
public void setPower(double power) {
POWER = power;
}
public CrosshairDemo() {
super();
this.setContentPane(new CrosshairDemo.MyDemoPanel());
}
public static class MyDemoPanel extends JPanel implements Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
Thread t = new Thread((Runnable) this);
private TimeSeries series;
private final ChartPanel chartPanel;
private final JFreeChart chart = this.createChart();
public MyDemoPanel() {
super(new BorderLayout());
this.chartPanel = new ChartPanel(this.chart);
this.chartPanel.setPreferredSize(new Dimension(200, 550));
this.chartPanel.setLocation(getWidth() + 50, getHeight() + 30);
this.chartPanel.setDomainZoomable(true);
this.chartPanel.setRangeZoomable(true);
this.add(this.chartPanel);
t.start();
}
private JFreeChart createChart() {
XYDataset dataset1 = this.createDataset("Random 1", 100.0D, new Minute(), 200);
JFreeChart chart1 = ChartFactory.createTimeSeriesChart("Crosshair Demo 1", "Time of Day", "Value", dataset1);
XYPlot plot = (XYPlot)chart1.getPlot();
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setDomainCrosshairVisible(true);
plot.setDomainCrosshairLockedOnData(false);
plot.setRangeCrosshairVisible(false);
return chart1;
}
private XYDataset createDataset(String name, double base, RegularTimePeriod start, int count) {
this.series = new TimeSeries(name);
RegularTimePeriod period = start;
double value = base;
for(int i = 0; i < count; ++i) {
this.series.add(period, value);
period = period.next();
value *= 1.0D + (Math.random() - 0.495D) / 10.0D;
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(this.series);
return dataset;
}
#Override
public void run() {
// TODO Auto-generated method stub
while(true) {
int value = (int) POWER; //this.slider.getValue();
XYPlot plot = (XYPlot)this.chart.getPlot();
ValueAxis domainAxis = plot.getDomainAxis();
Range range = domainAxis.getRange();
double c = domainAxis.getLowerBound() + (double)value / 100.0D * range.getLength();
plot.setDomainCrosshairValue(c);
}
}
}
Right now it's "attached" to the top (NORTH) of my JPanel:
Current chart position:
I would appreciate any help, because I have no more idea how to position this chart freely, therefore, I need your help guys.
I want to know how my console output can be save in a notepad file?
import java.awt.EventQueue;
public class HLS1 {
private JFrame frmHttpsLiveStreaming;
private JTextField textField;
// file is accessed to the whole class
private File file;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HLS1 window = new HLS1();
window.frmHttpsLiveStreaming.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public HLS1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmHttpsLiveStreaming = new JFrame();
frmHttpsLiveStreaming.setTitle("HTTPS Live Streaming");
frmHttpsLiveStreaming.setBounds(100, 100, 494, 112);
frmHttpsLiveStreaming.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmHttpsLiveStreaming.getContentPane().setLayout(null);
JButton btnBrowse = new JButton("Open File");
btnBrowse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("Argument:" + arg0);
JFileChooser fs = new JFileChooser(new File("c:\\"));
fs.setDialogTitle("Open a file");
fs.setFileFilter(new FileTypeFilter(".m3u8", ""));
fs.setFileFilter(new FileTypeFilter(".m3u", ""));
fs.showOpenDialog(null);
file = fs.getSelectedFile();
textField.setText(file.getAbsolutePath());
}
});
btnBrowse.setBounds(336, 7, 89, 23);
frmHttpsLiveStreaming.getContentPane().add(btnBrowse);
JButton btnNewButton_1 = new JButton("Clear");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField.setText("");
}
});
btnNewButton_1.setBounds(237, 39, 89, 23);
frmHttpsLiveStreaming.getContentPane().add(btnNewButton_1);
JLabel lblUrl = new JLabel("URL");
lblUrl.setBounds(83, 11, 24, 14);
frmHttpsLiveStreaming.getContentPane().add(lblUrl);
textField = new JTextField();
textField.setBounds(116, 11, 210, 19);
frmHttpsLiveStreaming.getContentPane().add(textField);
textField.setColumns(10);
JButton btnNewButton = new JButton("Check");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
List<String> fileArray = new ArrayList<String>();
List<String> errors = new ArrayList<String>();
String regex = "^(https?|ftp|file)://[-a-zA-Z0-9+&##/%?=~_|!:,.;]*[-a-zA-Z0-9+&##/%=~_|]";
Scanner s = null;
if(textField.getText().matches(regex)){
URL url = new URL(textField.getText());
s= new Scanner(url.openStream());
}else{
s = new Scanner(new BufferedReader(new FileReader(file)));
}
if(s != null){
while(s.hasNextLine()){
String line = s.nextLine();
if(!line.isEmpty()){
fileArray.add(line);
}
System.out.println(line);
}
}
s.close();
errors.addAll(validateEXTM3U(fileArray));
for (String error : errors) {
System.out.println(error);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
btnNewButton.setBounds(126, 39, 89, 23);
frmHttpsLiveStreaming.getContentPane().add(btnNewButton);
}
private List<String> validateEXTM3U(List<String> fileArray){
List<String> errors = new ArrayList<String>();
String tag = fileArray.get(0);
if(!tag.equals("#EXTM3U")){
errors.add("First line in the menifest file is not #EXTM3U");
}
return errors;
}
}
It could be a hacky solution , but if you are running in windows or linux then you can pipe / redirect it.
java HLS1 > notepad.txt
if not what you are looking for , then why not using something called log4j ?
Why don't you write your own utility that has an public static void output(String output) method. Then instead of using System.out.println("...") you call output("...") then in your output(String output) method you can do anything with the output, like first write to the file, then print to the console.
Hope this helps.
When I run my program the JButtons don't appear until i change the size of the screen(setResizable = true;).
here is my code:
public class MainMenu extends JPanel {
Kingdomcraft kd;
Screen screen;
JButton playSP;
JButton playMP;
JButton settings;
JButton fullscreen;
JButton quit;
JButton createWorld;
JButton addServer;
JSlider sound;
JSlider light;
JList worldList;
JList serverList;
JTextField worldName;
JTextField serverName;
JTextField serverIP;
JButton addNewWorld;
JButton addNewServer;
private Preferences prefs;
private int soundLevel;
private int lightLevel;
public static boolean isFullscreen = false;
public static boolean serverNameFilled = false;
public static boolean serverIPFilled = false;
public void run() {
kd = new Kingdomcraft();
screen = new Screen();
playSP = new JButton("Singleplayer");
playMP = new JButton("Multiplayer");
settings = new JButton("Settings");
fullscreen = new JButton("Fullscreen");
quit = new JButton("Quit");
createWorld = new JButton("Create World");
addServer = new JButton("Add Server");
sound = new JSlider();
light = new JSlider();
prefs = Preferences.userNodeForPackage(MainMenu.class);
soundLevel = prefs.getInt("SOUND_LEVEL", 50);
lightLevel = prefs.getInt("LIGHT_LEVEL", 100);
worldList = new JList();
serverList = new JList();
worldName = new JTextField();
serverName = new JTextField();
serverIP = new JTextField();
addNewWorld = new JButton("Add");
addNewServer = new JButton("Add");
this.setBackground(Color.BLACK);
if (kd.inMainMenu) {
add(playSP);
playSP.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
remove(sound);
remove(light);
remove(fullscreen);
remove(addServer);
remove(serverName);
remove(serverIP);
remove(addNewServer);
repaint();
add(createWorld);
createWorld.setSize(110, 25);
createWorld.setLocation(playSP.getX() - (playSP.getWidth() / 2) - 5, playSP.getY() + 35);
createWorld.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
add(worldName);
worldName.setSize(110, 25);
worldName.setLocation(createWorld.getX(), createWorld.getY() + 35);
worldName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
add(addNewWorld);
addNewWorld.setSize(110, 25);
addNewWorld.setLocation(worldName.getX(), worldName.getY() + 35);
}
});
}
});
}
});
add(playMP);
playMP.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
remove(sound);
remove(light);
remove(fullscreen);
remove(createWorld);
remove(worldName);
remove(addNewWorld);
repaint();
add(addServer);
addServer.setSize(100, 25);
addServer.setLocation(playMP.getX() - (playMP.getWidth() / 2) - 5, playMP.getY() + 35);
addServer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
add(serverName);
serverName.setSize(100, 25);
serverName.setLocation(addServer.getX(), addServer.getY() + 35);
serverName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainMenu.serverNameFilled = true;
}
});
add(serverIP);
serverIP.setSize(100, 25);
serverIP.setLocation(serverName.getX(), serverName.getY() + 35);
serverIP.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainMenu.serverIPFilled = true;
}
});
if (serverNameFilled && serverIPFilled) {
add(addNewServer);
addNewServer.setSize(100, 25);
addNewServer.setLocation(serverIP.getX(), serverIP.getY() + 35);
addNewServer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
}
}
});
}
});
add(settings);
settings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
remove(createWorld);
remove(addServer);
remove(worldName);
remove(serverName);
remove(serverIP);
remove(addNewWorld);
remove(addNewServer);
repaint();
add(sound);
sound.setSize(settings.getWidth(), settings.getHeight());
sound.setLocation(settings.getX() + (settings.getWidth() / 2) + 5, settings.getY() + 35);
sound.setOpaque(false);
sound.setMinimum(0);
sound.setMaximum(100);
sound.setValueIsAdjusting(true);
sound.setValue(soundLevel);
sound.setToolTipText("Audio: " + soundLevel + "%");
sound.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
soundLevel = sound.getValue();
sound.setToolTipText("Audio: " + soundLevel + "%");
prefs.putInt("SOUND_LEVEL", soundLevel);
}
});
add(light);
light.setSize(settings.getWidth(), settings.getHeight());
light.setLocation(sound.getX(), sound.getY() + 35);
light.setOpaque(false);
light.setMinimum(50);
light.setMaximum(150);
light.setValueIsAdjusting(true);
light.setValue(lightLevel);
light.setToolTipText("Brightness: " + lightLevel + "%");
light.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
lightLevel = light.getValue();
light.setToolTipText("Brightness: " + lightLevel + "%");
prefs.putInt("LIGHT_LEVEL", lightLevel);
}
});
add(fullscreen);
fullscreen.setSize(100, settings.getHeight());
fullscreen.setLocation(settings.getX() + (settings.getWidth() / 2) - 50, light.getY() + 35);
fullscreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainMenu.isFullscreen = true;
}
});
}
});
add(quit);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(ABORT);
}
});
}
}
}
I understand that this is a lot of code to skim through but I'm just plain stumped.
When you add a UI component in swing, you need to call the component's revalidate method for the changes to take effect.
Can't tell exactly what you are doing but I'm not sure you should be continually removing/adding individual components.
Maybe you should be use a Card Layout which will allow to you remove/add panels based on the specific function the user requests.
I have two classes, a GUI and a Customer class. The GUI builds the frame and button, and the Customer class gets the info from a database server. I have the ActionPerformed in the Customer class, but it doesn't appear to be noticing when I click the button. Any help is extremely appreciated!
GUI Class:
class GUI {
private static JFrame frame;
public static JTextField textField;
public static JButton btnGetInfo = new JButton("Get Info");
public static JTextArea textArea = new JTextArea();
public static void main (String args [])
throws SQLException {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
GUI window = new GUI();
frame = new JFrame();
frame.setBounds(100, 100, 630, 470);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setBounds(10, 179, 594, 241);
frame.getContentPane().add(textArea);
textField = new JTextField();
textField.setBounds(255, 69, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
JButton btnClearScreen = new JButton("Clear Screen");
btnClearScreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.setText("");
}
});
btnClearScreen.setBounds(492, 11, 112, 23);
frame.getContentPane().add(btnClearScreen);
JLabel lblEnterCustomerId = new JLabel("Enter Customer ID (1-6)");
lblEnterCustomerId.setBounds(240, 43, 153, 14);
frame.getContentPane().add(lblEnterCustomerId);
btnGetInfo.setBounds(255, 115, 89, 23);
frame.getContentPane().add(btnGetInfo);
window.frame.setVisible(true);
}
}
Customer Class:
public class Customer implements ActionListener {
public static void getInfoButton() {
GUI.btnGetInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("TEST");
String getCustID = GUI.textField.getText();
String query = ("select * from customers where CUSTID =" + getCustID);
final String user, pass;
user = "asdf";
pass = "asdf";
try{
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#asdf",user,pass);
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery (query);
while (rset.next ())
{
GUI.textArea.append((rset.getString("CUSTID") + " - " + rset.getString("CUSTSSN")
+ " - " + rset.getString("LNAME") + " - " + rset.getString("FNAME") + " - " +
rset.getString("STREET") + " - " + rset.getString("CITY") + " - " + rset.getString("STATE") +
" - " + rset.getString("ZIP") + " - " + rset.getString("PHONE") + System.getProperty("line.separator")
+ System.getProperty("line.separator")));
}
}
catch (SQLException e)
{
System.out.println ("Could not load the db"+e);
}
}});
}
#Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
public static JButton btnGetInfo = new JButton("Get Info");
You should add the actionlistener to this
btnGetInfo.addActionListener(new Customer());
Your Customer should just look like this
public class Customer implements ActionListener {
// delete the uneccessary
#Override
public void actionPerformed(ActionEvent arg0) {
...
}
}
Unnecessary code
public static void getInfoButton() {
GUI.btnGetInfo.addActionListener(new ActionListener() {