APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

Similar documents
Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

FirstSwingFrame.java Page 1 of 1

G51PRG: Introduction to Programming Second semester Applets and graphics

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

SampleApp.java. Page 1

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Dr. Hikmat A. M. AbdelJaber

Example: Building a Java GUI

Example: Building a Java GUI

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

// autor igre Ivan Programerska sekcija package mine;

AnimatedImage.java. Page 1

Graphic User Interfaces. - GUI concepts - Swing - AWT

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

RobotPlanning.java Page 1

class BankFilter implements Filter { public boolean accept(object x) { BankAccount ba = (BankAccount) x; return ba.getbalance() > 1000; } }

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

AP CS Unit 11: Graphics and Events

User interfaces and Swing

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

Using Several Components

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Answer on question #61311, Programming & Computer Science / Java

import java.applet.applet; import java.applet.audioclip; import java.net.url; public class Vjesala2 {

Building Java Programs Bonus Slides

Dr. Hikmat A. M. AbdelJaber

Chapter 9 Designing Graphical User Interfaces (GUIs)

Multi-Threading : Doing Things in Parallel

Multi-Threading : Doing Things in Parallel

MTAT Systems Modelling Statechart modeling, simulation and execution using Yakindu

COMP16121 Sample Code Lecture 1

H212 Introduction to Software Systems Honors

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Programming Languages and Techniques (CIS120)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Java Coordinate System

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Lecture 3: Java Graphics & Events

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Page 1 of 16. Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

EPITA Première Année Cycle Ingénieur. Atelier Java - J5

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Section Basic graphics

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

CSIS 10A Assignment 7 SOLUTIONS

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

/* Write a Program implementing GUI based Calculator using Swing */

AP CS Unit 12: Drawing and Mouse Events

import javax.swing.*; import java.awt.*; import java.awt.event.*;

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM503 Programming B. Peter Schneider-Kamp.

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

6.092 Introduction to Software Engineering in Java January (IAP) 2009

Introduction. Introduction

Client-side GUI. A simple Swing-gui for searching for proudcts

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

Graphical User Interfaces in Java - SWING

Introduction to the JAVA UI classes Advanced HCI IAT351

News! Feedback after Lecture 4! About Java and OOP!

Graphical User Interfaces (GUIs)

Chapter Nine: Interfaces and Polymorphism. Big Java by Cay Horstmann Copyright 2008 by John Wiley & Sons. All rights reserved.

3/7/2012. Chapter Nine: Interfaces and Polymorphism. Chapter Goals

10/27/2011. Chapter Goals

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

RAIK 183H Examination 2 Solution. November 10, 2014

State Application Using MVC

Graphical User Interface

PART 22. Java GUI Library SWT GUI Library SWING GUI Library Swing First Program

1 Looping Constructs (4 minutes, 2 points)

Clasa frsin.java: import java.awt.*; import javax.swing.*;

Graphical User Interfaces 2

Advanced Java Unit 6: Review of Graphics and Events

We are on the GUI fast track path

encompass a group of features for building Graphical User Interfaces (GUI).

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Java for Interfaces and Networks (DT3010, HT10)

Multimedia Programming

CS193k, Stanford Handout #16

RAIK 183H Examination 2 Solution. November 11, 2013

COMP Assignment #10 (Due: Monday, March 11:30pm)

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

CSCI 201L Midterm Written Summer % of course grade

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

THE UNIVERSITY OF AUCKLAND

CS193k, Stanford Handout #10. Threads 4 / RMI

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Transcription:

APPENDIX CLASS NODE AS TREE OBJECT public class Node public int data; public Node left; public Node right; public Node parent; public Node(int i) data=i; PROCEDURE BUILDING TREE public class Tree public Node root; public void cekroot() System.out.println("nilai root : "+root.data); public boolean isempty() return root==null; public void insert(int i) Node temp = new Node(i); Node y = null; Node x = root; if (isempty()) System.out.println("nilai "+i+" menjadi root"); root = temp; else while(x!= null) A

y = x; if(i < x.data) x= x.left; else x = x.right; if( i < y.data) if(y.left == null) y.left=temp; System.out.println("nilai "+i+" masuk sebelah kiri "+y.data); else y.right = temp; System.out.println("nilai "+i+" masuk sebelah kanan "+y.data); else if(y.right == null) y.right = temp; System.out.println("nilai "+i+" masuk sebelah kanan "+y.data); else y.left=temp; System.out.println("nilai "+i+" masuk sebelah kiri "+y.data); public void min() Node temp=root; while(temp.left!=null) temp=temp.left; System.out.println("nilai min :" +temp.data); public void max() B

Node temp=root; while(temp.right!=null) temp=temp.right; System.out.println("nilai max:" +temp.data); public void cetak(node i) Node temp=i; if(temp!=null) cetak(temp.parent); System.out.println(temp.data); cetak(temp.left); cetak(temp.right); public void printnode() System.out.println("Cetak Tree"); cetak(root); DisplayThread dt = new DisplayThread(); public void maxheap(node root, Node prev, PaintTree painttree) if(root==null) return; try maxheap(root.left,root,painttree); maxheap(root.right,root,painttree); if( prev!= null && root.data < prev.data) swapper(root,prev); prev = root; maxheap(prev, prev,painttree); catch (Exception e) e.printstacktrace(); C

public void swapper(node node1, Node node2) int temp= node1.data; node1.data = node2.data; node2.data = temp; public void swapmax(painttree painttree) maxheap(root, root,painttree); public void printmax() System.out.println("\nHasil swap:"); cetak(root); public Node[] dualheap(node root) Node data = root; Node result[] = new Node[2]; Tree tree1 = new Tree(); tree1.root = root.left; Tree tree2 = new Tree(); tree2.root = root.right; result[0] = tree1.root; result[1] = tree2.root; cetakheap(root); System.out.println("\n===Tree Split Pertama==="); tree1.cetakheap(tree1.root); System.out.println("\n===Tree Split kedua==="); tree2.cetakheap(tree2.root); return result; public void cetakdual() dualheap(root); public void cetakheap(node root) if(root == null) return; if(this.root.data == root.data ) System.out.println("nilai "+root.data+" Sebagai root"); if(root.right!= null) D

System.out.println("nilai "+root.right.data+" masuk sebelah kanan "+root.data); cetakheap(root.right); if(root.left!= null) System.out.println("nilai "+root.left.data+" masuk sebelah kiri "+root.data); cetakheap(root.left); public void deletetree() root = null; System.out.println("Tree deleted"); CLASS TREE DISPLAY import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.border; public class TreeDisplay extends JPanel private Tree tree; private JTextField jtfkey = new JTextField(5); private PaintTree painttree; private PaintTree painttree1; private PaintTree painttree2; private JButton jbtinsert = new JButton("Insert"); private JButton jbtsorting = new JButton("Sorting"); private JButton jbtclear = new JButton("Clear"); private Timer timer; public TreeDisplay(Tree tree) this.tree = tree; painttree = new PaintTree(tree); SwingUtilities.invokeLater(new Runnable() public void run() setui(); ); E

public void setui() this.setlayout(new BorderLayout()); add(painttree, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.add(new JLabel("Enter a key: ")); panel.add(jtfkey); panel.add(jbtinsert); panel.add(jbtclear); panel.add(jbtsorting); panel.add(jbtsorting); add(panel, BorderLayout.SOUTH); jbtclear.addactionlistener(new ActionListener() public void actionperformed(actionevent e) tree.deletetree(); panel.repaint(); painttree.repaint(); ); jbtsorting.addactionlistener(new ActionListener() @Override public void actionperformed(actionevent e) painttree.swapmax(painttree); tree.cetakdual(); //painttree1.dualheap(1); //dualheapdisp(painttree1); //painttree2.dualheap(2); //dualheapdisp2(painttree2); //painttree2.repaint(); painttree.timer.start(); painttree.revalidate(); painttree.repaint(); ); jbtinsert.addactionlistener(new ActionListener() public void actionperformed(actionevent e) int key = Integer.parseInt(jtfKey.getText()); tree.insert(key); F

); painttree.repaint(); CLASS PAINT TREE import java.awt.graphics; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.sql.time; import javax.swing.timer; import javax.swing.jpanel; import java.awt.color; import java.awt.graphics2d; import java.awt.font; class PaintTree extends JPanel private int radius = 20; private int vgap = 50; private Tree tree; public Timer timer; public Timer timer2; public PaintTree(Tree tree2) this.tree = tree2; protected void paintcomponent(graphics g) super.paintcomponent(g); Font font = new Font("Verdana", Font.BOLD, 12); g.setfont(font); 4); if (tree.root!= null) displaytree(g, tree.root, getwidth() / 2, 30, getwidth() / public void dualheap(int i) Node dual[] = tree.dualheap(tree.root); if(i == 1) tree.root = dual[0]; G

else if(i == 2) tree.root = dual[1]; public void cetakdual() dualheap(tree.root); private void displaytree(graphics g, Node root, int x, int y, int hgap) g.drawoval(x - radius, y - radius, 2 * radius, 2 * radius); g.drawstring(root.data + "", x - 6, y + 4); g.setcolor(color.black); if(root.right!=null) g.drawstring(root.data + "", x - 6, y + 4); g.setcolor(color.red); else g.setcolor(color.blue); if(root.left!=null) g.drawstring(root.data + "", x - 6, y + 4); g.setcolor(color.magenta); else g.setcolor(color.green); 2); if (root.left!= null) connectleftchild(g, x - hgap, y + vgap, x, y); displaytree(g, root.left, x - hgap, y + vgap, hgap / if (root.right!= null) connectrightchild(g, x + hgap, y + vgap, x, y); displaytree(g, root.right, x + hgap, y + vgap, hgap / 2); public Tree gettree() return tree; H

public void settree(tree tree) this.tree = tree; private void connectleftchild(graphics g, int x1, int y1, int x2, int y2) double d = Math.sqrt(vGap * vgap + (x2 - x1) * (x2 - x1)); int x11 = (int)(x1 + radius * (x2 - x1) / d); int y11 = (int)(y1 - radius * vgap / d); int x21 = (int)(x2 - radius * (x2 - x1) / d); int y21 = (int)(y2 + radius * vgap / d); g.drawline(x11, y11, x21, y21); private void connectrightchild(graphics g, int x1, int y1, int x2, int y2) double d = Math.sqrt(vGap * vgap + (x2 - x1) * (x2 - x1)); int x11 = (int)(x1 - radius * (x1 - x2) / d); int y11 = (int)(y1 - radius * vgap / d); int x21 = (int)(x2 + radius * (x1 - x2) / d); int y21 = (int)(y2 + radius * vgap / d); g.drawline(x11, y11, x21, y21); public void maxheap(node root, Node prev, PaintTree painttree) if(root==null) return; timer = new Timer(2000, new ActionListener() @Override public void actionperformed(actionevent e) maxheap(root.left,root,painttree); maxheap(root.right,root,painttree); prev.data) if( prev!= null && root.data < swapper(root,prev); //prev = root; Node prev2 = root; maxheap(prev2, prev2,painttree); repaint(); ); timer.start(); I

public void swapper(node node1, Node node2) int temp= node1.data; node1.data = node2.data; node2.data = temp; public void swapmax(painttree painttree) maxheap(tree.root, tree.root,painttree); CLASS DISPLAY THREAD public class DisplayThread implements Runnable PaintTree painttree; public PaintTree getpainttree() return painttree; public void setpainttree(painttree painttree) this.painttree = painttree; @Override public void run() painttree.repaint(); CLASS MAIN GUI import java.awt.borderlayout; import java.awt.dimension; import java.awt.frame; import java.awt.graphics; import java.awt.graphics2d; import javax.swing.jtextfield; import javax.swing.swingutilities; import javax.swing.japplet; J

import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; public class MainGui extends JPanel public MainGui() public static void main(string[] args) JFrame frame; frame = new JFrame("Simulation"); frame.setdefaultcloseoperation(jframe.exit_on_close); JButton jbtinsert = new JButton("Insert"); JButton jbtdelete = new JButton("Delete"); JTextField jtfkey = new JTextField(5); JPanel panel = new JPanel(); panel.add(new JLabel("Enter a key: ")); panel.add(jtfkey); panel.add(jbtinsert); panel.add(jbtdelete); Tree a=new Tree(); /*a.insert(5); a.insert(4); a.insert(7); a.insert(6); a.insert(9); a.insert(10); a.insert(8);*/ SwingUtilities.invokeLater(new Runnable() public void run() TreeDisplay treedisplay = new TreeDisplay(a); frame.getcontentpane().add(treedisplay); ); frame.pack(); frame.setsize(new Dimension(1360, 700)); frame.setvisible(true); K

L

M