Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图形输出在java中不起作用_Java_Swing_User Interface_Graphics - Fatal编程技术网

图形输出在java中不起作用

图形输出在java中不起作用,java,swing,user-interface,graphics,Java,Swing,User Interface,Graphics,我试图通过扩展JPanel类和使用图形方法来绘制一个客户机队列。但是,我无法从图形框架获得输出。 这是我想画画的班级 public class Simulating extends JPanel{ // Server server; //private ArrayList<JPanel> remember=new ArrayList<JPanel>(server.no_list);s public Simulating() {} pro

我试图通过扩展JPanel类和使用图形方法来绘制一个客户机队列。但是,我无法从图形框架获得输出。 这是我想画画的班级

public class Simulating extends JPanel{

    // Server server;
    //private ArrayList<JPanel> remember=new ArrayList<JPanel>(server.no_list);s
    public Simulating() {}

    protected void colorareComponente(Graphics gr) {
        super.paintComponent(gr);
        int x = 0;
        for (int i = 0; i <Server.listele.length; i++) {
            int y = 0;
            // desenez casele
            deseneazaCasa(gr, x, y,i);
            for (int j = 0; j <Server.listele[i].getSize(); j++) {
                y =y+ 25;
                // desenezClienti
                //  SimulareCoada.cozi[i].getClientCurent(j).getId()
                int id =  Server.listele[i].getTask(j).getId()+ 1;
                deseneazaClient(gr, x, y, id);
            }
            x =x+ 100;
        }

    }
    private void deseneazaCasa(Graphics g, int x, int y,int i) {
        g.setColor(Color.BLACK);
        g.fillRect(x, y, 100, 20);
        g.setColor(Color.BLUE);
        g.drawString("Server"+i+1 , x + 20, y + 20);
        this.repaint();
    }

    private void deseneazaClient(Graphics g, int x, int y, int id) {
        g.setColor(Color.CYAN);
        g.fillOval(x, y, 35, 35);
        g.drawString(Integer.toString(id), x + 8, y + 16);
        this.repaint();
    }

    public void rewrite() {
         this.repaint();
    }
}
但是没有;似乎没有任何输出。 我正在用另一种方法调用sim来重新绘制帧:

public void run(){
    this.initializeServer();

    for (Server.currentTime = 0; Server.taskCount > 0; Server.currentTime++){
        int TimeHours =calculateTimeHour(currentTime);
        int TimeMinutes = calculateTimeMinute(currentTime);
        writeHourConsole(TimeHours,TimeMinutes);
        writeHourLog(TimeHours,TimeMinutes);
        this.Log.setLog(keepingLog);
        this.Log.repaint();
        int val=0;
        if(val==0) {
            for (int i = 0; i < taskurile.size(); i++){
                if (taskurile.get(i).getGettingTime() == Server.currentTime){
                    int index = taskurile.get(i).chooseLista(this);
                    this.listele\[index\].addTaskLast(taskurile.get(i));            
                    System.out.println("\n Taskul " + i + " a fost preluat la " + decimal.format(TimeHours) + ":" + decimal.format(TimeMinutes) + "si este procesat pentru " +  taskurile.get(i).getProcessTime());
                    Server.appendLog("\n Taskul " + i + " a fost preluat la " + decimal.format(TimeHours) + ":" + decimal.format(TimeMinutes) + "si este procesat pentru " +  taskurile.get(i).getProcessTime()+ "de serverul " + taskurile.get(i).chooseLista(this));
                    sim.rewrite();
                    this.Log.setLog(keepingLog);
                    this.Log.repaint();
                }
            }
        }
    }
}
public void run(){
this.initializeServer();
对于(Server.currentTime=0;Server.taskCount>0;Server.currentTime++){
int TimeHours=calculateTimeHour(当前时间);
int TimeMinutes=calculateTimeMinute(当前时间);
writeHourConsole(时间小时、时间分钟);
写入日志(时间小时、时间分钟);
this.Log.setLog(keepingLog);
this.Log.repaint();
int-val=0;
如果(val==0){
对于(int i=0;i
这就是我得到的:

有一个日志面板,可以跟踪正常工作的事件。我没有错误或异常消息

有人能解释一下为什么它不起作用吗?
谢谢大家!

读一下。正如上面的教程链接所解释的,您永远不会直接调用paintComponent()方法。自定义绘制代码被添加到paintComponent()方法中。本教程提供了一些可供下载和使用的示例。
public void run(){
    this.initializeServer();

    for (Server.currentTime = 0; Server.taskCount > 0; Server.currentTime++){
        int TimeHours =calculateTimeHour(currentTime);
        int TimeMinutes = calculateTimeMinute(currentTime);
        writeHourConsole(TimeHours,TimeMinutes);
        writeHourLog(TimeHours,TimeMinutes);
        this.Log.setLog(keepingLog);
        this.Log.repaint();
        int val=0;
        if(val==0) {
            for (int i = 0; i < taskurile.size(); i++){
                if (taskurile.get(i).getGettingTime() == Server.currentTime){
                    int index = taskurile.get(i).chooseLista(this);
                    this.listele\[index\].addTaskLast(taskurile.get(i));            
                    System.out.println("\n Taskul " + i + " a fost preluat la " + decimal.format(TimeHours) + ":" + decimal.format(TimeMinutes) + "si este procesat pentru " +  taskurile.get(i).getProcessTime());
                    Server.appendLog("\n Taskul " + i + " a fost preluat la " + decimal.format(TimeHours) + ":" + decimal.format(TimeMinutes) + "si este procesat pentru " +  taskurile.get(i).getProcessTime()+ "de serverul " + taskurile.get(i).chooseLista(this));
                    sim.rewrite();
                    this.Log.setLog(keepingLog);
                    this.Log.repaint();
                }
            }
        }
    }
}