Skip to main content

Posts

Showing posts with the label code sample

Implement a simple calculator (detailed comments on JAVA code)

 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.NumberFormat;//Keep decimals public class SimpleCalculation extends JFrame{     Frame frame = new JFrame();     Frame MistakeWindons = new JFrame();     private JButton SumBtn = new JButton("SUM");     private JButton SubBtn = new JButton("SUB");     private JButton MulBtn = new JButton("MUL");     private JButton DivBtn = new JButton("DIV");     private JButton Reset = new JButton("Reset");     private JTextField FristCount = new JTextField(5);     private JTextField SecondCount = new JTextField(5);     private JTextField Result = new JTextField(10);     private Label Design = new Label("Design by CodingPush");     private Font Ft = new Font("Helvetica", Font.BOLD, 18);//Set font     public SimpleCalculation() {         frame.setResizable(false);//Set...

Disk scheduling algorithm java code

 The first step is to create a CSCAN class public class CSCAN {     public int m=0; //used to store the initial position of the head      public boolean Run=true;      public int sum=0;      public void Check(int a[],int n,int position){          int temp;          for (int i = n; i> 0; i--)          {    // Bubble Sort               for (int j = 0; j <i; j++){     if (a[j]> a[j + 1]) {// Compare the sizes in order          temp = a[j]; // put the big number in front          a[j] = a[j + 1];          a[j + 1] = temp;     }               }          }          while (Run)          {     ...

How to write a program for calendar in Java

calendar for a given month of a given year, or of the current month and year. import java.util.*; import java.text.*; /** Print a month page. * Only works for the Western calendar. */ public class CalendarPage { /** The names of the months */ String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /** The days in each month. */ public final static int dom[] = { 31, 28, 31, 30, /* jan feb mar apr */ 31, 30, 31, 31, /* may jun jul aug */ 30, 31, 30, 31 /* sep oct nov dec */ }; /** Compute which days to put where, in the Cal panel */ public void print(int mm, int yy) { /** The number of days to leave blank at the start of this month */ int leadGap = 0; System.out.print(months[mm]); // print month and year System.out.print(" "); System.out.print(y...