Advertisement
greedydev

ACM Task 3

Oct 26th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. import acm.graphics.*;
  2. import acm.program.GraphicsProgram;
  3.  
  4. public class Task3 extends GraphicsProgram {
  5.     public void run() {
  6.         final int WIDTH = 1000;
  7.         final int HEIGHT = 600;
  8.  
  9.         this.setSize(WIDTH, HEIGHT);
  10.  
  11.         int centerX = WIDTH/2;
  12.         int centerY = HEIGHT/2;
  13.  
  14.         double blockWidth = WIDTH/4.1;
  15.         double blockHeight = HEIGHT/8.0;
  16.  
  17.         double fontSize = (WIDTH > HEIGHT) ? HEIGHT/35.0 : WIDTH/35.0;
  18.         String fontSettings = "Arial-" + (int)fontSize;
  19.  
  20.         addBlock(centerX-blockWidth/2, centerY-blockHeight*2, blockWidth, blockHeight, fontSettings,
  21.                 "Program");
  22.         addBlock(centerX-blockWidth/2, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
  23.                 "ConsoleProgram");
  24.         addBlock(centerX-blockWidth*2, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
  25.                 "GraphicsProgram");
  26.         addBlock(centerX+blockWidth, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
  27.                 "DialogProgram");
  28.  
  29.         // Link to ConsoleProgram block
  30.         GLine consoleProgramLink = new GLine(centerX, centerY-blockHeight, centerX, centerY+blockHeight);
  31.         add(consoleProgramLink);
  32.  
  33.         // Link to GraphicsProgram block
  34.         GLine graphicsProgramLink = new GLine(centerX, centerY-blockHeight, centerX-blockWidth*1.5, centerY+blockHeight);
  35.         add(graphicsProgramLink);
  36.  
  37.         // Link to DialogProgram block
  38.         GLine dialogProgramLink = new GLine(centerX, centerY-blockHeight, centerX+blockWidth*1.5, centerY+blockHeight);
  39.         add(dialogProgramLink);
  40.     }
  41.  
  42.     private void addBlock(double x, double y, double blockWidth, double blockHeight, String fontSettings, String labelText) {
  43.         GRect programBlock = new GRect(x, y, blockWidth, blockHeight);
  44.         GLabel blockLabel = new GLabel(labelText);
  45.         blockLabel.setFont(fontSettings);
  46.         double blockLabelX = x+(blockWidth-blockLabel.getWidth())/2.0;
  47.         double blockLabelY = y+(blockHeight+blockLabel.getHeight())/2.0;
  48.         blockLabel.setLocation(blockLabelX, blockLabelY);
  49.  
  50.         add(programBlock);
  51.         add(blockLabel);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement