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

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

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

// autor igre Ivan Programerska sekcija package mine;

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

2018/2/5 话费券企业客户接入文档 语雀

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

2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Layouts and Components Exam

Final Examination Semester 2 / Year 2010

2D Graphics. Shape Models, Drawing, Selection. CS d Graphics 1

Object-Oriented Programming Design. Topic : Graphics Programming GUI Part I

Final Examination Semester 2 / Year 2012

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Graphic User Interfaces. - GUI concepts - Swing - AWT

Final Examination Semester 2 / Year 2011

Chapter 12 Advanced GUIs and Graphics

Dr. Hikmat A. M. AbdelJaber

Adding Buttons to StyleOptions.java

CSCI 201L Midterm Written Summer % of course grade

Programming Graphics (P1 2006/2007)

8/23/2011. Chapter Goals

2/9/2012. Chapter Two: Using Objects. Chapter Goals

Object-oriented programming in Java (2)

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet

CSCI 201L Midterm Written SOLUTION Summer % of course grade

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Laborator 3 Aplicatii Java

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

Assignment 2. Application Development

Chapter 2 Using Objects

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

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

AP CS Unit 12: Drawing and Mouse Events

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

H212 Introduction to Software Systems Honors

Programming graphics

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

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

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

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

First Name: AITI 2004: Exam 2 July 19, 2004

Check out ThreadsIntro project from SVN. Threads and Animation

MODEL UPDATES MANIPULATES USER

Graphic Interface Programming II Events and Threads. Uppsala universitet

AnimatedImage.java. Page 1

Swing Programming Example Number 2

Programmierpraktikum

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

CSIS 10A Assignment 7 SOLUTIONS

First Name: AITI 2004: Exam 2 July 19, 2004

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Ingineria Sistemelor de Programare

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

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

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week.

Sample Solution Assignment 5. Question R3.1

Attempt FOUR questions Marking Scheme Time: 120 mins

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

CSE wi Final Exam 3/12/18. Name UW ID#

CSE 331 Final Exam 6/7/16

P 6.3) import java.util.scanner;

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

Lecture 5: Java Graphics

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

JFrame & JLabel. By Iqtidar Ali

Java Programming Lecture 6

CompSci 230 S Programming Techniques. Basic GUI Components

Java Programming Summer 2008 LAB. Thursday 8/21/2008

9Introducing. Concurrency with Threads

Gracefulness of TP-Tree with Five Levels Obtained by Java Programming

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

CS111: PROGRAMMING LANGUAGE II

AplusBug dude = new AplusBug(); A+ Computer Science -

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

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

COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )

CSE wi Final Exam 3/12/18 Sample Solution

AP CS Unit 11: Graphics and Events

Lecture 3: Java Graphics & Events

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Chapter 2 Using Objects. Copyright 2014 by John Wiley & Sons. All rights reserved. 1

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Chapter 7: A First Look at GUI Applications

Assignment #3 (Due 4/4/2017)

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

CS Exam 3 - Spring 2010

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

Course overview: Introduction to programming concepts

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.

1 Looping Constructs (4 minutes, 2 points)

Using Several Components

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

We are on the GUI fast track path

Transcription:

1

Clasa frsin.java: import java.awt.*; import javax.swing.*; public class frsin extends JFrame { private sin2d jpanel1 = new sin2d(); private JCheckBox cbcreion = new JCheckBox(); private JCheckBox cbfond = new JCheckBox(); private JRadioButton rbg1 = new JRadioButton(); private JRadioButton rbg2 = new JRadioButton(); private JRadioButton rbg3 = new JRadioButton(); private JLabel jlabel1 = new JLabel(); private JLabel jlabel2 = new JLabel(); //acest cod se scrie cu mana //asigura gruparea logica a //butoanelor JRadioButton private ButtonGroup bg; //gata public frsin() { try { jbinit(); catch (Exception e) { e.printstacktrace(); private void jbinit() throws Exception { this.getcontentpane().setlayout( null ); this.setsize(new Dimension(482, 300)); this.settitle( "Grafic sin(x)" ); jpanel1.setbounds(new Rectangle(0, 10, 375, 255)); cbcreion.settext("creion"); cbcreion.setbounds(new Rectangle(385, 40, 80, 25)); cbcreion.additemlistener(new ItemListener() { cbcreion_itemstatechanged(e); ); cbfond.settext("fond"); cbfond.setbounds(new Rectangle(385, 65, 80, 20)); cbfond.additemlistener(new ItemListener() { cbfond_itemstatechanged(e); ); rbg1.settext("1"); rbg1.setbounds(new Rectangle(390, 155, 40, 20)); //acest JRadioButton este //implicit selectat rbg1.setselected(true); rbg1.additemlistener(new ItemListener() { rb1_itemstatechanged(e); ); rbg2.settext("2"); rbg2.setbounds(new Rectangle(390, 175, 40, 25)); rbg2.additemlistener(new ItemListener() { rbg2_itemstatechanged(e); ); rbg3.settext("3"); 2

rbg3.setbounds(new Rectangle(390, 195, 40, 25)); rbg3.additemlistener(new ItemListener() { rbg3_itemstatechanged(e); ); jlabel1.settext("culori"); jlabel1.setbounds(new Rectangle(390, 15, 70, 25)); jlabel1.setfont(new Font("Tahoma", 1, 13)); jlabel2.settext("grosime"); jlabel2.setbounds(new Rectangle(390, 125, 65, 20)); jlabel2.setfont(new Font("Tahoma", 1, 13)); this.getcontentpane().add(jlabel2, null); this.getcontentpane().add(jlabel1, null); this.getcontentpane().add(rbg3, null); this.getcontentpane().add(rbg2, null); this.getcontentpane().add(rbg1, null); this.getcontentpane().add(cbfond, null); this.getcontentpane().add(cbcreion, null); this.getcontentpane().add(jpanel1, null); //acest cod se scrie cu mana bg = new ButtonGroup(); bg.add(rbg1); bg.add(rbg2); bg.add(rbg3); private void cbcreion_itemstatechanged(itemevent e) { jpanel1.culoarescris = cbcreion.isselected()?color.blue:color.black; private void cbfond_itemstatechanged(itemevent e) { jpanel1.culoareafond = cbfond.isselected()? Color.GREEN:Color.YELLOW ; private void rb1_itemstatechanged(itemevent e) { jpanel1.grosimescris=1.0f; private void rbg2_itemstatechanged(itemevent e) { jpanel1.grosimescris=2.0f; private void rbg3_itemstatechanged(itemevent e) { jpanel1.grosimescris=3.0f; public static void main(string[] args) { frsin fr = new frsin(); fr.setdefaultcloseoperation(jframe.exit_on_close); fr.setvisible(true); 3

Clasa sin2d.java: import java.awt.basicstroke; import java.awt.color; import java.awt.graphics; import java.awt.graphics2d; import java.awt.geom.line2d; import javax.swing.jpanel; public class sin2d extends JPanel { //atribute publice //variabile de instanta public Color culoarescris, culoareafond; public float grosimescris; //constructor public sin2d() { culoareafond = Color.ORANGE; culoarescris = Color.BLACK; grosimescris = 1.0f; public void paintcomponent(graphics g) { super.paintcomponent(g); Graphics2D g2 = (Graphics2D)g; //variabile locale //latimea JPanel-ului double LX = this.getwidth(); //inaltimea JPanel-ului double LY = this.getheight(); //Originea in sistemul de axe al graficului double x0 = 0; double y0 = LY/2.; double x1,y1,x2,y2; x1=x0; y1=y0; //axa Ox g2.draw(new Line2D.Double(x0, y0, x0+lx, y0)); //axa Oy g2.draw(new Line2D.Double(x0, y0-ly/2, x0, y0+ly)); LX=LX/2./Math.PI; LY=LY/2.-1.; //setare culoare fond this.setbackground(culoareafond); //setare culoare scris g2.setpaint(culoarescris); //setare grosime scris g2.setstroke(new BasicStroke(grosimeScris)); //trasare grafic sin(x) for(double x=0.;x<2.*math.pi;x+=0.01) { x2=x0+lx*x; y2=y0-ly*math.sin(x); //y2=y0-ly*math.sin(x)*x/5.; g2.draw(new Line2D.Double(x1, y1, x2, y2)); x1=x2; y1=y2; System.out.printf("%15.5f %15.12f\n",x,Math.sin(x)); g2.drawstring("sin(x) ", (int)x0, (int)y0); 4

5

6