Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import acm.graphics.*;
- import acm.program.GraphicsProgram;
- public class Task3 extends GraphicsProgram {
- public void run() {
- final int WIDTH = 1000;
- final int HEIGHT = 600;
- this.setSize(WIDTH, HEIGHT);
- int centerX = WIDTH/2;
- int centerY = HEIGHT/2;
- double blockWidth = WIDTH/4.1;
- double blockHeight = HEIGHT/8.0;
- double fontSize = (WIDTH > HEIGHT) ? HEIGHT/35.0 : WIDTH/35.0;
- String fontSettings = "Arial-" + (int)fontSize;
- addBlock(centerX-blockWidth/2, centerY-blockHeight*2, blockWidth, blockHeight, fontSettings,
- "Program");
- addBlock(centerX-blockWidth/2, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
- "ConsoleProgram");
- addBlock(centerX-blockWidth*2, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
- "GraphicsProgram");
- addBlock(centerX+blockWidth, centerY+blockHeight, blockWidth, blockHeight, fontSettings,
- "DialogProgram");
- // Link to ConsoleProgram block
- GLine consoleProgramLink = new GLine(centerX, centerY-blockHeight, centerX, centerY+blockHeight);
- add(consoleProgramLink);
- // Link to GraphicsProgram block
- GLine graphicsProgramLink = new GLine(centerX, centerY-blockHeight, centerX-blockWidth*1.5, centerY+blockHeight);
- add(graphicsProgramLink);
- // Link to DialogProgram block
- GLine dialogProgramLink = new GLine(centerX, centerY-blockHeight, centerX+blockWidth*1.5, centerY+blockHeight);
- add(dialogProgramLink);
- }
- private void addBlock(double x, double y, double blockWidth, double blockHeight, String fontSettings, String labelText) {
- GRect programBlock = new GRect(x, y, blockWidth, blockHeight);
- GLabel blockLabel = new GLabel(labelText);
- blockLabel.setFont(fontSettings);
- double blockLabelX = x+(blockWidth-blockLabel.getWidth())/2.0;
- double blockLabelY = y+(blockHeight+blockLabel.getHeight())/2.0;
- blockLabel.setLocation(blockLabelX, blockLabelY);
- add(programBlock);
- add(blockLabel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement