Home > Back-end >  For help, why each time to draw out the first string
For help, why each time to draw out the first string

Time:12-14

Package pageReplace;
Import the Java. The awt. *;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;
Import the Java. The awt. Image. The ImageObserver;
Import the Java. Text. AttributedCharacterIterator;

The import javax.mail. Swing. *;
Public class PageReplacePanel extends JPanel implements ActionListener, Runnable
{
Private int x0=70, y0=70;
Private int stringStart_x stringStart_y;//the starting position of the string
Private int length=0; The length of the array//page
Private int index;
Private FIFO FIFO.//objects of first in first out)
Private JTextField pageNum;
Private Thread panelThread;
Private JButton fifoButton;
Public PageReplacePanel ()
{
JLabel label=new JLabel (" page number: ");
PageNum=new JTextField (10);
FifoButton=new JButton (" FIFO page replacement algorithm ");
This. The add (label);
This. The add (pageNum);
This. The add (fifoButton);
FifoButton. AddActionListener (this);
Fifo=new fifo ();
The index=0;
}
Public void paint (Graphics g)
{
Super. Paint (g);
for(int i=0; iG.d rawLine (x0 + I * 30, y0, x0 + I * 30, y0 + 60);
for(int j=0; j<4. J++)
G.d rawLine (x0, y0 + j * 20, x0 + 30, length * y0 + j * 20);
}
Public String getRandom ()
{
Int Max=10;
Int min=1;
Return (int) (min + Math. The random () * (Max - min + 1)) + "";
}
@ Override
Public void the run () {
//TODO Auto - generated method stub
Length=fifo. GetInputpageLength ();
Fifo. SetTime (0);
Enclosing repaint (x0, y0, 600400);
While (index{

Fifo. DoFIFO (index);
Enclosing getGraphics (). DrawString (fifo) getOutString (), stringStart_x, stringStart_y - 20);
for(int j=0; jEnclosing getGraphics (). DrawString (fifo) getFifoLinkedList () get (j), stringStart_x, stringStart_y + j * 20);
If (fifo) getIsHit ())
Enclosing getGraphics (). DrawString (" tick ", stringStart_x - 5, stringStart_y + 60);
index++;
StringStart_x +=30;
Try {
Thread.sleep(500);
} the catch (Exception e) {
e.printStackTrace();
}
}
Enclosing getGraphics (). DrawString (" hit number: "+ fifo. GetTime () +" : from "+ fifo. GetTime ()/length, 300300);
}
@ Override
Public void actionPerformed (an ActionEvent e) {
int num;
Try {
Num=Integer. The parseInt (pageNum getText (), toString ());
{} to catch (a NumberFormatException exception)
Num=15;
}
If (num> 15)
Num=15;
String [] page=new String (num);
for(int i=0; i{
Page [I]=getRandom ();
System. The out. Print (page [I] + "");
}
System.out.println();
Fifo. SetInputpage (page);
If (um participant etSource ()==fifoButton)
{

Fifo. SetOutString (" ");
StringStart_x=85;
StringStart_y=85;
The index=0;
PanelThread=new Thread (this);
PanelThread. Start ();
}
}
}
  • Related