Answered step by step
Verified Expert Solution
Question
1 Approved Answer
how write this in my code can you Can you write it : In order to add a train to the Train.txt file, the admin
how write this in my code can you Can you write it: In order to add a train to the "Train.txt" file, the admin needs to enter an id. The id is
unique, so before adding the train we need to check if there is no other train in the file
with the same id.
The Admin should choose two different stations and define the maximum number of
passengers that could take the train
/*
*
*/
package com.mycompany.login;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.swing. *;
/**
*
* @author Haya2
*/
public class Train extends JFrame {
private JButton b1,b2;
private JTextField t1,t2 ;
private JLabel l1,l2,l3,l4;
private JComboBox cmb1,cmb2;
public Train (String title) {
super(title);
this.setVisible(true);
this.setSize(3000, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1=new JLabel("Train id");
t1=new JTextField(10);
JPanel p1= new JPanel(new FlowLayout(FlowLayout.LEFT));
p1.add(l1);
p1.add(t1);
l2=new JLabel("departure station");
String[] st ={"Buraydah,Riyadh,Jaddah"};
cmb1= new JComboBox(st);
JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT));
p2.add(l2);
p2.add(cmb1);
l3=new JLabel("arrival station");
String[] st1 ={"Buraydah,Riyadh,Jaddah"};
cmb2= new JComboBox(st);
JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT));
p3.add(l3);
p3.add(cmb2);
l4=new JLabel("Max Passengers");
t1=new JTextField(10);
JPanel p4= new JPanel(new FlowLayout(FlowLayout.LEFT));
p4.add(l4);
p4.add(t2);
b1= new JButton("add");
b2= new JButton("Cancel");
JPanel p5= new JPanel();
p5.add(b1);
p5.add(b2);
JPanel p=(JPanel)this.getContentPane();
p.setLayout(new GridLayout(5,1));
p.add(p1);
p.add(p2);
p.add(p3);
p.add(p4);
p.add(p5);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
// TODO code application logic here
Train r = new Train("add Train");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started