Java-based LRU page Scheduling Algorithm

Source: Internet
Author: User

RT: Let's take a look. It's a very simple algorithm, but it's not flexible. After all, it's just done according to the requirements of the experiment. You can give more comments. Thank you.

 

Import java. AWT. container;
Import java. AWT. flowlayout;
Import java. AWT. gridlayout;
Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;

Import javax. Swing. jbutton;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;
Import javax. Swing. joptionpane;
Import javax. Swing. jpanel;
Import javax. Swing. jtextfield;

Public class static_storing {
 
Public static int I = 0;
Public static_storing (){
Jframe APP = new jframe ("webpage-based virtual storage ");
Container c = app. getcontentpane ();
Jlabel L1 = new jlabel ("page number ");
Jlabel L2 = new jlabel ("flag ");
Jlabel [] L = {New jlabel ("0"), new jlabel ("1"), new jlabel ("2"), new jlabel ("3 "), new jlabel ("4"), new jlabel ("5"), new jlabel ("6 ")};
Jlabel l3 = new jlabel ("command address stream to be accessed ");
Final jlabel L4 = new jlabel ("click to start access! ");
Final int [] visit = };
Jbutton B = new jbutton ("access ");
Final int [] usual = {0, 1, 2, 3 };
Final jtextfield [] T = {New jtextfield ("1", 10), new jtextfield ("1"), new jtextfield ("1 "), new jtextfield ("1"), new jtextfield ("0"), new jtextfield ("0"), new jtextfield ("0 ")};
B. addactionlistener (New actionlistener (){
Public void actionreceivmed (actionevent e ){
// Todo auto-generated method stub
If (I> = visit. length)
L4.settext ("the command stream is fully accessed! End the process! ");
Else
{
If (T [visit [I]. gettext (). Equals ("1 "))
{
L4.settext ("Access command stream" + visit [I] + "in primary storage, direct access ");
Int K = 0;
Int temp;
For (k = 0; k <usual. length; k ++)
If (visit [I] = usual [k])
Break;
If (k = 1)
{
Temp = usual [0];
Usual [0] = visit [1];
Usual [1] = temp;
}
Else
If (k = 2)
{
Temp = usual [0];
Visit [2] = visit [1];
Usual [0] = visit [2];
Visit [1] = temp;
}
Else
If (k = 3)
{
Temp = usual [0];
Visit [3] = visit [2];
Visit [2] = visit [1];
Usual [0] = visit [2];
Visit [1] = temp;
}
Temp = usual [k];
Usual [0] = visit [I];

}
Else
{
L4.settext ("the accessed command stream is not in the primary storage, and is transferred to the page" + visit [I] + "to bring up the page" + usual [3]);
T [visit [I]. settext ("1 ");
T [usual [3]. settext ("0 ");
Int temp;
Temp = usual [2];
Usual [2] = usual [1];
Usual [1] = usual [0];
Usual [0] = visit [I];
Usual [3] = temp;
}
I ++;
}
}

});
Jpanel p1 = new jpanel (New gridlayout (9, 0 ));
P1.add (L1); p1.add (L2 );
For (int K = 0; k <t. length; k ++)
{
P1.add (L [k]); p1.add (T [k]);
}
P1.add (L3 );
P1.setsize (300,300 );
C. Add (P1); C. Add (L3 );
Jpanel P2 = new jpanel (New gridlayout (1, 0 ));
P2.add (B); p2.add (L4 );
P2.setsize (20, 20 );
C. Add (P2 );
C. setlayout (New flowlayout (flowlayout. Center ));
App. setsize (450,350 );
App. setdefaclocloseoperation (jframe. exit_on_close );
App. setvisible (true );
}
Public static void main (string [] arg0 ){
Static_storing A = new static_storing ();
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.