SlideShare a Scribd company logo
1 of 9
Download to read offline
Import java.awt.*;
Import acm.program.*;
Import acm.graphics.*;
public class Sierpinski extends GraphicsProgram
{
public void run()
{
GRect box = new GRect(20, 20, 242, 242);
box.setFilled(true);
add(box);
drawGasket(20, 20, 243);
}
private void drawFigure(int x, int y, int side) {
int sub = side / 3;
GRect box = new GRect(x + sub, y + sub, sub - 1, sub - 1);
box.setFilled(true);
box.setColor(Color.WHITE);
add(box);
if (sub >= 3) {
drawFigure(x, y, sub);
drawFigure(x + sub, y, sub);
drawFigure(x + 2 * sub, y, sub);
drawFigure(x, y + sub, sub);
drawFigure(x + 2 * sub, y + sub, sub);
drawFigure(x, y + 2 * sub, sub);
drawFigure(x + sub, y + 2 * sub, sub);
drawFigure(x + 2 * sub, y + 2 * sub, sub);
}
}
C.8 SQUARE in recursive method:-
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SierpinskiCarpet extends JPanel implements ActionListener
{
public static void main(String[] args)
{
JFrame window = new JFrame("Sierpinski Carpet");
window.setContentPane( new SierpinskiCarpet() );
window.pack();
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int x = Math.max(10, (screensize.width - window.getWidth()) / 2);
int y = Math.max(10, (screensize.height - window.getHeight()) / 2);
window.setLocation(x,y);
window.setVisible(true);
}
private int level;
private JRadioButton[] levelButton;
private JCheckBox[][] regionCheckbox;
private Display display;
private class Display extends JPanel
{
Display()
{
setBackground(Color.WHITE);
setPreferredSize(new Dimension(729,729));
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
drawCarpet(g,level,0,0,729);
}
}
public SierpinskiCarpet()
{
setLayout(new BorderLayout(3,3));
setBackground(Color.GRAY);
setBorder(BorderFactory.createLineBorder(Color.GRAY,3));
display = new Display();
add(display,BorderLayout.CENTER);
Box controls = Box.createVerticalBox();
controls.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
controls.setBackground(Color.WHITE);
controls.setOpaque(true);
add(controls, BorderLayout.EAST);
controls.add(new JLabel("Controls"));
controls.add(Box.createVerticalStrut(30));
levelButton = new JRadioButton[7];
ButtonGroup grp = new ButtonGroup();
for (int i = 0; i < 7; i++)
{
levelButton[i] = new JRadioButton("Recursion Level " + i);
grp.add(levelButton[i]);
levelButton[i].addActionListener(this);controls.add(levelButton[i]);
}
level = 4;
levelButton[4].setSelected(true);
regionCheckbox = new JCheckBox[3][3];
JPanel checks = new JPanel();
checks.setLayout(new GridLayout(3,3,5,5));
for (int r = 0; r < 3; r++)
{
for (int c = 0; c < 3; c++)
{
regionCheckbox[r][c] = new JCheckBox();
checks.add(regionCheckbox[r][c]);
regionCheckbox[r][c].addActionListener(this);
regionCheckbox[r][c].setSelected(true);
}
}
checks.setMaximumSize(new Dimension(90,90));
checks.setAlignmentX(LEFT_ALIGNMENT);
checks.setBackground(Color.WHITE);
regionCheckbox[1][1].setSelected(false);
controls.add(Box.createVerticalStrut(30));
controls.add(new JLabel("Regions To Include:"));
controls.add(Box.createVerticalStrut(15));
controls.add(checks);
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
for (int i = 0; i < 7; i++)
{
if (src == levelButton[i])
{
level = i;
break;
}
}
}
private void drawCarpet(Graphics g, int level, int x, int y, int size)
{
g.fillRect(x,y,size,size);
}
}
Solution
Import java.awt.*;
Import acm.program.*;
Import acm.graphics.*;
public class Sierpinski extends GraphicsProgram
{
public void run()
{
GRect box = new GRect(20, 20, 242, 242);
box.setFilled(true);
add(box);
drawGasket(20, 20, 243);
}
private void drawFigure(int x, int y, int side) {
int sub = side / 3;
GRect box = new GRect(x + sub, y + sub, sub - 1, sub - 1);
box.setFilled(true);
box.setColor(Color.WHITE);
add(box);
if (sub >= 3) {
drawFigure(x, y, sub);
drawFigure(x + sub, y, sub);
drawFigure(x + 2 * sub, y, sub);
drawFigure(x, y + sub, sub);
drawFigure(x + 2 * sub, y + sub, sub);
drawFigure(x, y + 2 * sub, sub);
drawFigure(x + sub, y + 2 * sub, sub);
drawFigure(x + 2 * sub, y + 2 * sub, sub);
}
}
C.8 SQUARE in recursive method:-
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SierpinskiCarpet extends JPanel implements ActionListener
{
public static void main(String[] args)
{
JFrame window = new JFrame("Sierpinski Carpet");
window.setContentPane( new SierpinskiCarpet() );
window.pack();
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int x = Math.max(10, (screensize.width - window.getWidth()) / 2);
int y = Math.max(10, (screensize.height - window.getHeight()) / 2);
window.setLocation(x,y);
window.setVisible(true);
}
private int level;
private JRadioButton[] levelButton;
private JCheckBox[][] regionCheckbox;
private Display display;
private class Display extends JPanel
{
Display()
{
setBackground(Color.WHITE);
setPreferredSize(new Dimension(729,729));
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
drawCarpet(g,level,0,0,729);
}
}
public SierpinskiCarpet()
{
setLayout(new BorderLayout(3,3));
setBackground(Color.GRAY);
setBorder(BorderFactory.createLineBorder(Color.GRAY,3));
display = new Display();
add(display,BorderLayout.CENTER);
Box controls = Box.createVerticalBox();
controls.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
controls.setBackground(Color.WHITE);
controls.setOpaque(true);
add(controls, BorderLayout.EAST);
controls.add(new JLabel("Controls"));
controls.add(Box.createVerticalStrut(30));
levelButton = new JRadioButton[7];
ButtonGroup grp = new ButtonGroup();
for (int i = 0; i < 7; i++)
{
levelButton[i] = new JRadioButton("Recursion Level " + i);
grp.add(levelButton[i]);
levelButton[i].addActionListener(this);controls.add(levelButton[i]);
}
level = 4;
levelButton[4].setSelected(true);
regionCheckbox = new JCheckBox[3][3];
JPanel checks = new JPanel();
checks.setLayout(new GridLayout(3,3,5,5));
for (int r = 0; r < 3; r++)
{
for (int c = 0; c < 3; c++)
{
regionCheckbox[r][c] = new JCheckBox();
checks.add(regionCheckbox[r][c]);
regionCheckbox[r][c].addActionListener(this);
regionCheckbox[r][c].setSelected(true);
}
}
checks.setMaximumSize(new Dimension(90,90));
checks.setAlignmentX(LEFT_ALIGNMENT);
checks.setBackground(Color.WHITE);
regionCheckbox[1][1].setSelected(false);
controls.add(Box.createVerticalStrut(30));
controls.add(new JLabel("Regions To Include:"));
controls.add(Box.createVerticalStrut(15));
controls.add(checks);
}
public void actionPerformed(ActionEvent e)
{
Object src = e.getSource();
for (int i = 0; i < 7; i++)
{
if (src == levelButton[i])
{
level = i;
break;
}
}
}
private void drawCarpet(Graphics g, int level, int x, int y, int size)
{
g.fillRect(x,y,size,size);
}
}

More Related Content

Similar to Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf

import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfanyacarpets
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...British Council
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfanjandavid
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfKARTIKINDIA
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfaakarcreations1
 
Creating an Uber Clone - Part XIX.pdf
Creating an Uber Clone - Part XIX.pdfCreating an Uber Clone - Part XIX.pdf
Creating an Uber Clone - Part XIX.pdfShaiAlmog1
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfaoneonlinestore1
 
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdfTic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdfinfomalad
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonEric Wendelin
 

Similar to Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf (20)

import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
Sokoban Game Development Using Java ( Updated using Screenshots & Class Diagr...
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
Awt
AwtAwt
Awt
 
No3
No3No3
No3
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
 
Creating an Uber Clone - Part XIX.pdf
Creating an Uber Clone - Part XIX.pdfCreating an Uber Clone - Part XIX.pdf
Creating an Uber Clone - Part XIX.pdf
 
662305 10
662305 10662305 10
662305 10
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Java programs
Java programsJava programs
Java programs
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdfimport java.awt.;import java.awt.event.;import javax.swing.;.pdf
import java.awt.;import java.awt.event.;import javax.swing.;.pdf
 
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdfTic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
Tic Tac Toe game with GUI written in java.SolutionAnswerimp.pdf
 
Graphical User Components Part 2
Graphical User Components Part 2Graphical User Components Part 2
Graphical User Components Part 2
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
 

More from apexcomputer54

Using gordon growth model Value of stock=Dividend paid(1+growt.pdf
    Using gordon growth model    Value of stock=Dividend paid(1+growt.pdf    Using gordon growth model    Value of stock=Dividend paid(1+growt.pdf
Using gordon growth model Value of stock=Dividend paid(1+growt.pdfapexcomputer54
 
not able to sign in .pdf
                     not able to sign in                              .pdf                     not able to sign in                              .pdf
not able to sign in .pdfapexcomputer54
 
moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf
                     moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf                     moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf
moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdfapexcomputer54
 
It would be . like for hydrated compound of.pdf
                     It would be  . like for hydrated compound of.pdf                     It would be  . like for hydrated compound of.pdf
It would be . like for hydrated compound of.pdfapexcomputer54
 
NO has got a strong bond because it has got an co.pdf
                     NO has got a strong bond because it has got an co.pdf                     NO has got a strong bond because it has got an co.pdf
NO has got a strong bond because it has got an co.pdfapexcomputer54
 
total number of moles of liquid increase, .pdf
                     total number of moles of liquid increase,        .pdf                     total number of moles of liquid increase,        .pdf
total number of moles of liquid increase, .pdfapexcomputer54
 
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdf
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdfYearscost of machin7 Year MACRS rateannual depreciation = cost.pdf
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdfapexcomputer54
 
what this meansSolutionwhat this means.pdf
what this meansSolutionwhat this means.pdfwhat this meansSolutionwhat this means.pdf
what this meansSolutionwhat this means.pdfapexcomputer54
 
we will use tables of normal distribution ( Z distribution)P( z .pdf
we will use tables of normal distribution ( Z distribution)P( z  .pdfwe will use tables of normal distribution ( Z distribution)P( z  .pdf
we will use tables of normal distribution ( Z distribution)P( z .pdfapexcomputer54
 
The Northeast blackout of 2003 was a widespread power outage that oc.pdf
The Northeast blackout of 2003 was a widespread power outage that oc.pdfThe Northeast blackout of 2003 was a widespread power outage that oc.pdf
The Northeast blackout of 2003 was a widespread power outage that oc.pdfapexcomputer54
 
The chemical reaction responsible for formation of water2H2+ O2--.pdf
The chemical reaction responsible for formation of water2H2+ O2--.pdfThe chemical reaction responsible for formation of water2H2+ O2--.pdf
The chemical reaction responsible for formation of water2H2+ O2--.pdfapexcomputer54
 
SolutionDomain name system is used to determine the IP address of.pdf
SolutionDomain name system is used to determine the IP address of.pdfSolutionDomain name system is used to determine the IP address of.pdf
SolutionDomain name system is used to determine the IP address of.pdfapexcomputer54
 
sample mean = population mean = 2.11standard deviation = popul.pdf
sample mean = population mean = 2.11standard deviation = popul.pdfsample mean = population mean = 2.11standard deviation = popul.pdf
sample mean = population mean = 2.11standard deviation = popul.pdfapexcomputer54
 
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdf
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdfPolymerase chain reaction (PCR) is a process used to replicate DNA i.pdf
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdfapexcomputer54
 
Glutamic acid and Lycine Hydrogen bonding could .pdf
                     Glutamic acid and Lycine Hydrogen bonding could .pdf                     Glutamic acid and Lycine Hydrogen bonding could .pdf
Glutamic acid and Lycine Hydrogen bonding could .pdfapexcomputer54
 
Need a clear pictureSolutionNeed a clear picture.pdf
Need a clear pictureSolutionNeed a clear picture.pdfNeed a clear pictureSolutionNeed a clear picture.pdf
Need a clear pictureSolutionNeed a clear picture.pdfapexcomputer54
 
For H2SO3 pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf
                     For H2SO3  pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf                     For H2SO3  pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf
For H2SO3 pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdfapexcomputer54
 
find the largest electronegativity difference (mo.pdf
                     find the largest electronegativity difference (mo.pdf                     find the largest electronegativity difference (mo.pdf
find the largest electronegativity difference (mo.pdfapexcomputer54
 
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdf
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdflet an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdf
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdfapexcomputer54
 

More from apexcomputer54 (20)

Using gordon growth model Value of stock=Dividend paid(1+growt.pdf
    Using gordon growth model    Value of stock=Dividend paid(1+growt.pdf    Using gordon growth model    Value of stock=Dividend paid(1+growt.pdf
Using gordon growth model Value of stock=Dividend paid(1+growt.pdf
 
not able to sign in .pdf
                     not able to sign in                              .pdf                     not able to sign in                              .pdf
not able to sign in .pdf
 
moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf
                     moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf                     moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf
moles of NH3 = 3417 = 2 moles of O2 = 4032 = 1..pdf
 
It would be . like for hydrated compound of.pdf
                     It would be  . like for hydrated compound of.pdf                     It would be  . like for hydrated compound of.pdf
It would be . like for hydrated compound of.pdf
 
NO has got a strong bond because it has got an co.pdf
                     NO has got a strong bond because it has got an co.pdf                     NO has got a strong bond because it has got an co.pdf
NO has got a strong bond because it has got an co.pdf
 
total number of moles of liquid increase, .pdf
                     total number of moles of liquid increase,        .pdf                     total number of moles of liquid increase,        .pdf
total number of moles of liquid increase, .pdf
 
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdf
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdfYearscost of machin7 Year MACRS rateannual depreciation = cost.pdf
Yearscost of machin7 Year MACRS rateannual depreciation = cost.pdf
 
what this meansSolutionwhat this means.pdf
what this meansSolutionwhat this means.pdfwhat this meansSolutionwhat this means.pdf
what this meansSolutionwhat this means.pdf
 
we will use tables of normal distribution ( Z distribution)P( z .pdf
we will use tables of normal distribution ( Z distribution)P( z  .pdfwe will use tables of normal distribution ( Z distribution)P( z  .pdf
we will use tables of normal distribution ( Z distribution)P( z .pdf
 
The Northeast blackout of 2003 was a widespread power outage that oc.pdf
The Northeast blackout of 2003 was a widespread power outage that oc.pdfThe Northeast blackout of 2003 was a widespread power outage that oc.pdf
The Northeast blackout of 2003 was a widespread power outage that oc.pdf
 
The chemical reaction responsible for formation of water2H2+ O2--.pdf
The chemical reaction responsible for formation of water2H2+ O2--.pdfThe chemical reaction responsible for formation of water2H2+ O2--.pdf
The chemical reaction responsible for formation of water2H2+ O2--.pdf
 
SolutionDomain name system is used to determine the IP address of.pdf
SolutionDomain name system is used to determine the IP address of.pdfSolutionDomain name system is used to determine the IP address of.pdf
SolutionDomain name system is used to determine the IP address of.pdf
 
sample mean = population mean = 2.11standard deviation = popul.pdf
sample mean = population mean = 2.11standard deviation = popul.pdfsample mean = population mean = 2.11standard deviation = popul.pdf
sample mean = population mean = 2.11standard deviation = popul.pdf
 
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdf
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdfPolymerase chain reaction (PCR) is a process used to replicate DNA i.pdf
Polymerase chain reaction (PCR) is a process used to replicate DNA i.pdf
 
Glutamic acid and Lycine Hydrogen bonding could .pdf
                     Glutamic acid and Lycine Hydrogen bonding could .pdf                     Glutamic acid and Lycine Hydrogen bonding could .pdf
Glutamic acid and Lycine Hydrogen bonding could .pdf
 
Need a clear pictureSolutionNeed a clear picture.pdf
Need a clear pictureSolutionNeed a clear picture.pdfNeed a clear pictureSolutionNeed a clear picture.pdf
Need a clear pictureSolutionNeed a clear picture.pdf
 
Li2SSolutionLi2S.pdf
Li2SSolutionLi2S.pdfLi2SSolutionLi2S.pdf
Li2SSolutionLi2S.pdf
 
For H2SO3 pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf
                     For H2SO3  pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf                     For H2SO3  pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf
For H2SO3 pK1 = 1.8 and pK2 = 7.2 and thus K1 = .pdf
 
find the largest electronegativity difference (mo.pdf
                     find the largest electronegativity difference (mo.pdf                     find the largest electronegativity difference (mo.pdf
find the largest electronegativity difference (mo.pdf
 
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdf
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdflet an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdf
let an=(-1)^(2n+1)and L=-1let us ahow that L=lim anindeed if e.pdf
 

Recently uploaded

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Import java.awt.; Import acm.program.; Import acm.graphics.;.pdf

  • 1. Import java.awt.*; Import acm.program.*; Import acm.graphics.*; public class Sierpinski extends GraphicsProgram { public void run() { GRect box = new GRect(20, 20, 242, 242); box.setFilled(true); add(box); drawGasket(20, 20, 243); } private void drawFigure(int x, int y, int side) { int sub = side / 3; GRect box = new GRect(x + sub, y + sub, sub - 1, sub - 1); box.setFilled(true); box.setColor(Color.WHITE); add(box); if (sub >= 3) { drawFigure(x, y, sub); drawFigure(x + sub, y, sub); drawFigure(x + 2 * sub, y, sub); drawFigure(x, y + sub, sub); drawFigure(x + 2 * sub, y + sub, sub); drawFigure(x, y + 2 * sub, sub); drawFigure(x + sub, y + 2 * sub, sub); drawFigure(x + 2 * sub, y + 2 * sub, sub); } } C.8 SQUARE in recursive method:- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SierpinskiCarpet extends JPanel implements ActionListener {
  • 2. public static void main(String[] args) { JFrame window = new JFrame("Sierpinski Carpet"); window.setContentPane( new SierpinskiCarpet() ); window.pack(); window.setResizable(false); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int x = Math.max(10, (screensize.width - window.getWidth()) / 2); int y = Math.max(10, (screensize.height - window.getHeight()) / 2); window.setLocation(x,y); window.setVisible(true); } private int level; private JRadioButton[] levelButton; private JCheckBox[][] regionCheckbox; private Display display; private class Display extends JPanel { Display() { setBackground(Color.WHITE); setPreferredSize(new Dimension(729,729)); } protected void paintComponent(Graphics g) { super.paintComponent(g); drawCarpet(g,level,0,0,729); } }
  • 3. public SierpinskiCarpet() { setLayout(new BorderLayout(3,3)); setBackground(Color.GRAY); setBorder(BorderFactory.createLineBorder(Color.GRAY,3)); display = new Display(); add(display,BorderLayout.CENTER); Box controls = Box.createVerticalBox(); controls.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); controls.setBackground(Color.WHITE); controls.setOpaque(true); add(controls, BorderLayout.EAST); controls.add(new JLabel("Controls")); controls.add(Box.createVerticalStrut(30)); levelButton = new JRadioButton[7]; ButtonGroup grp = new ButtonGroup(); for (int i = 0; i < 7; i++) { levelButton[i] = new JRadioButton("Recursion Level " + i); grp.add(levelButton[i]); levelButton[i].addActionListener(this);controls.add(levelButton[i]); } level = 4; levelButton[4].setSelected(true); regionCheckbox = new JCheckBox[3][3]; JPanel checks = new JPanel(); checks.setLayout(new GridLayout(3,3,5,5));
  • 4. for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { regionCheckbox[r][c] = new JCheckBox(); checks.add(regionCheckbox[r][c]); regionCheckbox[r][c].addActionListener(this); regionCheckbox[r][c].setSelected(true); } } checks.setMaximumSize(new Dimension(90,90)); checks.setAlignmentX(LEFT_ALIGNMENT); checks.setBackground(Color.WHITE); regionCheckbox[1][1].setSelected(false); controls.add(Box.createVerticalStrut(30)); controls.add(new JLabel("Regions To Include:")); controls.add(Box.createVerticalStrut(15)); controls.add(checks); } public void actionPerformed(ActionEvent e) { Object src = e.getSource(); for (int i = 0; i < 7; i++) { if (src == levelButton[i]) { level = i; break; } }
  • 5. } private void drawCarpet(Graphics g, int level, int x, int y, int size) { g.fillRect(x,y,size,size); } } Solution Import java.awt.*; Import acm.program.*; Import acm.graphics.*; public class Sierpinski extends GraphicsProgram { public void run() { GRect box = new GRect(20, 20, 242, 242); box.setFilled(true); add(box); drawGasket(20, 20, 243); } private void drawFigure(int x, int y, int side) { int sub = side / 3; GRect box = new GRect(x + sub, y + sub, sub - 1, sub - 1); box.setFilled(true); box.setColor(Color.WHITE); add(box); if (sub >= 3) { drawFigure(x, y, sub); drawFigure(x + sub, y, sub); drawFigure(x + 2 * sub, y, sub); drawFigure(x, y + sub, sub); drawFigure(x + 2 * sub, y + sub, sub); drawFigure(x, y + 2 * sub, sub);
  • 6. drawFigure(x + sub, y + 2 * sub, sub); drawFigure(x + 2 * sub, y + 2 * sub, sub); } } C.8 SQUARE in recursive method:- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SierpinskiCarpet extends JPanel implements ActionListener { public static void main(String[] args) { JFrame window = new JFrame("Sierpinski Carpet"); window.setContentPane( new SierpinskiCarpet() ); window.pack(); window.setResizable(false); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int x = Math.max(10, (screensize.width - window.getWidth()) / 2); int y = Math.max(10, (screensize.height - window.getHeight()) / 2); window.setLocation(x,y); window.setVisible(true); } private int level; private JRadioButton[] levelButton; private JCheckBox[][] regionCheckbox; private Display display; private class Display extends JPanel { Display() { setBackground(Color.WHITE); setPreferredSize(new Dimension(729,729)); }
  • 7. protected void paintComponent(Graphics g) { super.paintComponent(g); drawCarpet(g,level,0,0,729); } } public SierpinskiCarpet() { setLayout(new BorderLayout(3,3)); setBackground(Color.GRAY); setBorder(BorderFactory.createLineBorder(Color.GRAY,3)); display = new Display(); add(display,BorderLayout.CENTER); Box controls = Box.createVerticalBox(); controls.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); controls.setBackground(Color.WHITE); controls.setOpaque(true); add(controls, BorderLayout.EAST); controls.add(new JLabel("Controls")); controls.add(Box.createVerticalStrut(30)); levelButton = new JRadioButton[7]; ButtonGroup grp = new ButtonGroup(); for (int i = 0; i < 7; i++) { levelButton[i] = new JRadioButton("Recursion Level " + i); grp.add(levelButton[i]); levelButton[i].addActionListener(this);controls.add(levelButton[i]); }
  • 8. level = 4; levelButton[4].setSelected(true); regionCheckbox = new JCheckBox[3][3]; JPanel checks = new JPanel(); checks.setLayout(new GridLayout(3,3,5,5)); for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { regionCheckbox[r][c] = new JCheckBox(); checks.add(regionCheckbox[r][c]); regionCheckbox[r][c].addActionListener(this); regionCheckbox[r][c].setSelected(true); } } checks.setMaximumSize(new Dimension(90,90)); checks.setAlignmentX(LEFT_ALIGNMENT); checks.setBackground(Color.WHITE); regionCheckbox[1][1].setSelected(false); controls.add(Box.createVerticalStrut(30)); controls.add(new JLabel("Regions To Include:")); controls.add(Box.createVerticalStrut(15)); controls.add(checks); } public void actionPerformed(ActionEvent e) { Object src = e.getSource();
  • 9. for (int i = 0; i < 7; i++) { if (src == levelButton[i]) { level = i; break; } } } private void drawCarpet(Graphics g, int level, int x, int y, int size) { g.fillRect(x,y,size,size); } }