在Bluej中使用图形时遇到一些问题

时间:2018-08-20 13:54:27

标签: java

我正在机票系统的Bluej IDE上使用Java编写程序。我使用图形制作票证,而在jpanel上仅安装了一张。如何在jpanel上添加更多票证或是否有其他方法。 (仅适用于初学者,因此无需复杂的代码)。这是我的代码:

import java.awt.*;
import javax.swing.*;
import java.util.Random;
public class BullsEye extends JPanel {    
    public static void main(String args[]) {
        // Create our JFrame (main window) and make it 300 x 300
        FlightManager h = new FlightManager();
        h.Menu();

        JFrame frame = new JFrame("BullsEye");
        frame.setSize(300,300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create an instance of our class and add it to the frame
        BullsEye eye = new BullsEye();
            frame.add(eye);
            frame.setVisible(true);
    }
    // This method fires to draw our circles when we go to paint it on the frame
    public void paintComponent(Graphics g) {
           FlightManager app = new FlightManager();
           Flights f = new Flights();
           int p, x = 0;
           int num = 140;
           String place, flight, date, time;
           p = app.getPers();
           date = f.getDate();
           place = app.getPlace();
           flight = app.getFlight();
           time = app.getTime();
           String names[] = new String[p];
           names = app.getNames();
           super.paintComponent(g);
           g.setColor(Color.BLACK);
           g.drawRoundRect (10, 10, 1000, 300, 20, 20);
           g.setColor(Color.RED);  
           g.fillRoundRect(10,11,1001, 50, 20, 20);
           g.setColor(Color.WHITE);
           Font f1 = new Font ("Comic Sans MS", 1, 40); //Initializes the font
           g.setFont(f1); //Sets the font
           g.drawString("Europe Airlines", 350, 50);
           g.setColor(Color.BLACK);
           Font f2 = new Font ("Arial", 1, 20); //Initializes the font
           g.setFont(f2);
           g.setColor(Color.RED);
           g.drawString("Boarding Pass", 18, 90);
           g.setColor(Color.BLACK);
           g.drawString("Name of Passenger:", 18, 120);
           g.drawString(names[0], 18, 140);
           g.drawString("From:", 18, 190);
           g.drawString("Malta(MLA)", 18, 210);
           g.drawString("To:", 18, 250);
           g.drawString(place, 18, 270);
           g.drawString("Flight Number:", 400, 120);
           g.drawString(flight, 400, 140);
           g.drawString("Date:", 400, 190);
           g.drawString(date, 400, 210);
           g.drawString("Time:", 400, 260);
           g.drawString(time, 400, 280);
           g.drawString("Gate:", 800, 120);
           int g1 = (int)(Math.random()*11)+1;
           String gate = ""+g1;
           g.drawString(gate, 800, 140);
           g.drawString("Seat:", 800, 190);
           Random r = new Random();
           String alphabet = "ABCDEF";
           char c = alphabet.charAt(r.nextInt(alphabet.length()));
           String s = Character.toString(c);
           int g2 = (int)(Math.random()*22)+1;
           g.drawString(g2 + s, 800, 210);
    }
}

This picture includes what i've done so far with jpanel

0 个答案:

没有答案