import java.awt.*; import javax.swing.JApplet; import javax.swing.JOptionPane; import java.awt.event.*; import java.io.*; import java.util.Scanner; public class AppletDrawer extends JApplet { public String fname; public String objectType; public int point1; public int point2; public int point3; public int point4; public int temp; public void init() { AppletDrawer me = new AppletDrawer(); me.execute(); } public void execute() { Scanner sc = new Scanner(System.in); fname = JOptionPane.showInputDialog(null,"Enter name of file: "); fname = sc.nextLine(); try { Scanner f = new Scanner(new File(fname)); while (f.hasNextLine() == true) { objectType = f.next(); point1 = f.nextInt(); point2 = f.nextInt(); point3 = f.nextInt(); point4 = f.nextInt(); if (objectType == "oval") { temp = 1; }else if (objectType == "rect") { temp = 2; }else if (objectType == "line") { temp = 3; } repaint(); } f.close(); } catch (IOException e) { JOptionPane.showMessageDialog(null,"File Does not Exist.."); } } public void paint(Graphics g) { super.paint(g); if (temp == 1) { g.drawOval(point1, point2, point3, point4); }else if (temp == 2) { g.drawRect(point1, point2, point3, point4); }else if (temp == 3) { g.drawLine(point1, point2, point3, point4); } } }