Skip to content

Instantly share code, notes, and snippets.

View ahmednasserpro's full-sized avatar

ahmednasserpro

View GitHub Profile
@ahmednasserpro
ahmednasserpro / BouncingBall.java
Created July 17, 2019 01:22
Combine colliding bouncing balls
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class BouncingBall extends JFrame {
public BouncingBall() {
add(new BallControl());
}
@ahmednasserpro
ahmednasserpro / HTreeTextField.java
Last active July 10, 2019 14:58
Java draw h tree fractal
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HTreeTextField extends JFrame {
private JTextField tf = new JTextField("0", 5);
private HTree htree = new HTree();
public HTreeTextField() {
@ahmednasserpro
ahmednasserpro / KochSnowflake.java
Last active July 9, 2019 09:52
Koch snowflake fractles
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KochSnowflake extends JFrame {
private KochFrame koch = new KochFrame();
private JTextField tf = new JTextField("0", 5);
public KochSnowflake() {
JPanel panel = new JPanel();
@ahmednasserpro
ahmednasserpro / SierpinskiTriangle.java
Created July 5, 2019 10:06
SierpinskiTriangle drawing sierpinski triangles with java swing
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test {
public static void main(String[] args){
JFrame f = new SierpinskiTriangle();
f.setSize(300, 300);
f.setLocationRelativeTo(null);
@ahmednasserpro
ahmednasserpro / PlayConnectFourWithComputer.java
Created June 22, 2019 19:28
(Game: play connect four with computer) Revise Exercise 18.34 to play the game with the computer. The program lets the user make a move first, followed by a move by the computer. The minimum requirement is for the computer to make a legal move. You are encouraged to design good strategies for the computer to make intelligent moves
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PlayConnectFourWithComputer extends JFrame {
private Cell[][] cells = new Cell[6][7];
private char nextDisc = 'R';
private int[][] result;
private Timer timer = new Timer(100, new FlashingCells());
private JButton startOver = new JButton("Start Over");
@ahmednasserpro
ahmednasserpro / URLTest.java
Created June 11, 2019 06:32
(Retrieve files from Web) Write a Java program that retrieves a file from a Web server, as shown in Figure 17.32. The user interface includes a text field in which to enter the URL of the file name, a text area in which to show the file, and a button that can be used to submit an action. A label is added at the bottom of the applet to indicate t…
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import javax.swing.*;
public class URLTest extends JFrame {
@ahmednasserpro
ahmednasserpro / MyCalendar.java
Created June 10, 2019 20:41
(Display a calendar) Write a program that displays the calendar for the current month. You can use the Prior and Next buttons to show the calendar of the previous or next month. Display the dates in the current month in black and display the dates in the previous month and next month in gray
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
@ahmednasserpro
ahmednasserpro / FontTest.java
Created June 3, 2019 23:03
java test all font
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class FontTest extends JFrame {
String font = "Dialog";
int size = 12;
int fontStyleBold = 0;
@ahmednasserpro
ahmednasserpro / Histogram.java
Created June 1, 2019 01:40
Histogram class
import java.awt.*;
import javax.swing.*;
public class Histogram extends JPanel {
// Count the occurrences of 26 letters
private int[] count;
/**
* Set the count and display histogram
@ahmednasserpro
ahmednasserpro / BallOnCurveFrame.java
Last active May 27, 2019 11:57
Animation ball on curve
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BallOnCurveFrame extends JFrame {
private BallOnCurvePanel curvePanel = new BallOnCurvePanel();
BallOnCurveFrame() {
curvePanel.setBackground(Color.black);