대기열이 슈퍼마켓에서 어떻게 전개되는지 시뮬레이션 할 작업이 있으며 클라이언트가 들어가거나 저장소가있을 때마다 타이머를 사용하여 출력해야합니다. 슈퍼마켓에는 고객을 처리해야하는 대기열이 3 개 있습니다. 각 클라이언트에서 내 GUI에 도착 시간과 이탈 시간을 출력해야합니다. 각 큐에 동일한 타이머를 사용할 수 있습니까? (이들은 동시에 또는 동일한 시간 동안 출력을 시작해서는 안됨). 이벤트 클래스에서 매개 변수로 타이머를 전달하려고했지만 Null 포인터 예외가 발생합니다. 도움말 pls. Java 대기열 타이머
public void simulationPrep (Queue q,JPanel p,int time,Timer t, int selection)
{
TimeClass tc;
int queueCapacity=0;
float queueProcTime=0;
float tempSTMin, float tempSTMax;
tempSTMin=getServiceTimeMin();
tempSTMax=getServiceTimeMax();
queueCapacity = 10 + (int)(Math.random()*20);
queueProcTime = tempSTMin + (float)(Math.random()*tempSTMax);
q1.setCapacity(queueCapacity);
q1.setProcessingTime(queueProcTime);
tc = new TimeClass((int)(queueProcTime/queueCapacity),p,selection);
t = new Timer(time, tc);
t.start();
}
public void simulate()
{
if(getSelection()>=1)
{
simulationPrep(q1,p21,1000,timer1,1);
if(getSelection()>=2)
{
simulationPrep(q2,p22,1500,timer2,2);
if(getSelection()==3)
{
simulationPrep(q3,p23,1700,timer3,3);
}
}
}
}
public class TimeClass implements ActionListener
{
int counter;
JPanel p;
int selection;
public TimeClass(int counter,JPanel p,int selection)
{
this.counter = counter;
this.p = p;
this.selection = selection;
}
public void actionPerformed(ActionEvent e)
{
counter--;
if(counter>=1)
{
p.add(new JLabel("Hi "+counter));
p.updateUI();
}
if(counter<1)
{
p.add(new JLabel("Done"));
p.updateUI();
timer1.stop();
timer2.stop();
timer3.stop();
}
}
}
하나가 코드를 이해하지 않는 경우
내가 더 구체적인 수 있습니다, 문의하시기 바랍니다,하지만 여기 내 첫 번째 게시물 내가 가지 새로운 자바입니다. 당신의 Simulation.java 파일의Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at simulation.Simulation$TimeClass.actionPerformed(Simulation.java:229)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at simulation.Simulation$TimeClass.actionPerformed(Simulation.java:229)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
예외와 관련된 질문에 예외 스택 추적을 포함하면 훨씬 많은 도움을 얻을 수 있습니다. –
이것은 내가 얻는 것입니다 : –
'timer1','timer2' 및'timer3'는 어디에 선언되어 있습니까? – Jim