Announcement

Collapse
No announcement yet.

My java

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    My java

    don't mind me, I need to get some java files from school to home with no emails.



    WINDOW UTILITIES

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



    public class WindowUtilities {

    /** Tell system to use native look and feel, as in previous
    * releases. Metal (Java) LAF is the default otherwise.
    */

    public static void setNativeLookAndFeel() {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
    } catch(Exception e) {
    System.out.println("Error setting native LAF: " + e);
    }
    }

    /** A simplified way to see a JPanel or other Container.
    * Pops up a JFrame with specified Container as the content pane.
    */

    public static JFrame openInJFrame(Container content,
    int width,
    int height,
    String title,
    Color bgColor) {
    JFrame frame = new JFrame(title);
    frame.setBackground(bgColor);
    content.setBackground(bgColor);
    frame.setSize(width, height);
    frame.setContentPane(content);
    frame.addWindowListener(new ExitListener());
    frame.setVisible(true);
    return(frame);
    }

    /** Uses Color.white as the background color. */

    public static JFrame openInJFrame(Container content,
    int width,
    int height,
    String title) {
    return(openInJFrame(content, width, height, title, Color.white));
    }

    /** Uses Color.white as the background color, and the
    * name of the Container's class as the JFrame title.
    */

    public static JFrame openInJFrame(Container content,
    int width,
    int height) {
    return(openInJFrame(content, width, height,
    content.getClass().getName(),
    Color.white));
    }
    }




    EXITLISTENER



    import java.awt.*;
    import java.awt.event.*;

    public class ExitListener extends WindowAdapter {
    public void windowClosing(WindowEvent event) {
    System.exit(0);
    }
    }




    BOARD


    import javax.swing.*; // For JPanel, etc.
    import java.awt.*; // For Graphics, etc.
    import java.awt.geom.*; // For Ellipse2D, etc.
    import java.util.*;

    public class Board extends JPanel
    {
    int POBP1=0;
    int POBP2=0;
    int currentP1=0;
    int currentP2=0;
    int P1actions=0;
    int P2actions=0;

    private Rectangle2D.Double square = //OUTLINE
    new Rectangle2D.Double(250, 150, 750, 650);
    private Rectangle2D.Double p1box = //OUTLINE p1box
    new Rectangle2D.Double(50, 25, 175, 150);
    private Rectangle2D.Double p2box = //OUTLINE p2box
    new Rectangle2D.Double(1050, 25, 175, 150);
    private Rectangle2D.Double highlightbox = //OUTLINE current chosen guy
    new Rectangle2D.Double(1050, 200, 175, 400);


    //Verticals


    private Line2D.Double line =
    new Line2D.Double(300, 150, 300, 800);
    private Line2D.Double line1 =
    new Line2D.Double(350, 150, 350, 800);
    private Line2D.Double line2 =
    new Line2D.Double(400, 150, 400, 800);
    private Line2D.Double line3 =
    new Line2D.Double(450, 150, 450, 800);
    private Line2D.Double line4 =
    new Line2D.Double(500, 150, 500, 800);
    private Line2D.Double line5 =
    new Line2D.Double(550, 150, 550, 800);
    private Line2D.Double line6 =
    new Line2D.Double(600, 150, 600, 800);
    private Line2D.Double line7 =
    new Line2D.Double(650, 150, 650, 800);
    private Line2D.Double line8 =
    new Line2D.Double(700, 150, 700, 800);
    private Line2D.Double line9 =
    new Line2D.Double(750, 150, 750, 800);
    private Line2D.Double line10 =
    new Line2D.Double(800, 150, 800, 800);
    private Line2D.Double line11 =
    new Line2D.Double(850, 150, 850, 800);
    private Line2D.Double line12 =
    new Line2D.Double(900, 150, 900, 800);
    private Line2D.Double line13 =
    new Line2D.Double(950, 150, 950, 800);
    private Line2D.Double line14 =
    new Line2D.Double(1000, 150, 1000, 800);
    ;

    //Horizontals

    private Line2D.Double line15 =
    new Line2D.Double(250, 200, 1000, 200);
    private Line2D.Double line16 =
    new Line2D.Double(250, 250, 1000, 250);
    private Line2D.Double line17 =
    new Line2D.Double(250, 300, 1000, 300);
    private Line2D.Double line18 =
    new Line2D.Double(250, 350, 1000, 350);
    private Line2D.Double line19 =
    new Line2D.Double(250, 400, 1000, 400);
    private Line2D.Double line20 =
    new Line2D.Double(250, 450, 1000, 450);
    private Line2D.Double line21 =
    new Line2D.Double(250, 500, 1000, 500);
    private Line2D.Double line22 =
    new Line2D.Double(250, 550, 1000, 550);
    private Line2D.Double line23 =
    new Line2D.Double(250, 600, 1000, 600);
    private Line2D.Double line24 =
    new Line2D.Double(250, 650, 1000, 650);
    private Line2D.Double line25 =
    new Line2D.Double(250, 700, 1000, 700);
    private Line2D.Double line26 =
    new Line2D.Double(250, 750, 1000, 750);
    private Line2D.Double line27 =
    new Line2D.Double(250, 800, 1000, 800);






    public void paintComponent(Graphics g)
    {

    setBackground(Color.gray);
    Graphics2D g2d = (Graphics2D)g;
    g2d.draw(square);
    g2d.draw(p1box);
    g2d.draw(p2box);
    g2d.draw(highlightbox);
    g2d.draw(line);
    g2d.draw(line1);
    g2d.draw(line2);
    g2d.draw(line3);
    g2d.draw(line4);
    g2d.draw(line5);
    g2d.draw(line6);
    g2d.draw(line7);
    g2d.draw(line8);
    g2d.draw(line9);
    g2d.draw(line10);
    g2d.draw(line11);
    g2d.draw(line12);
    g2d.draw(line13);
    g2d.draw(line14);
    g2d.draw(line15);
    g2d.draw(line16);
    g2d.draw(line17);
    g2d.draw(line18);
    g2d.draw(line19);
    g2d.draw(line20);
    g2d.draw(line21);
    g2d.draw(line22);
    g2d.draw(line23);
    g2d.draw(line24);
    g2d.draw(line25);
    g2d.draw(line26);
    g2d.draw(line27);
    //Box text
    g2d.drawString( "PLAYER 1", 100, 50);
    g2d.drawString( "PLAYER 2", 1100, 50);
    g2d.drawString( "Points on board : "+POBP1, 75, 75 );
    g2d.drawString( "Points on board : "+POBP2, 1075, 75);
    g2d.drawString( "Current points : "+currentP1, 75, 100);
    g2d.drawString( "Current points : "+currentP2, 1075, 100);
    g2d.drawString( "Actions Remaining : "+P1actions, 75, 150);
    g2d.drawString( "Actions Remaining : "+P2actions, 1075, 150);

    //Highlight box

    // g2d.drawString("");
    // g2d.drawString("");
    // g2d.drawString("");
    // g2d.drawString("");


    }


    public static void main(String[] args) {
    WindowUtilities.openInJFrame(new Board(), 500, 500);


    }
    }

    #2
    rave
    Attached Files

    Comment


      #3
      import TerminalIO.*;
      import java.util.*;

      public class matrix
      {

      public static void main(String[] args)
      {
      KeyboardReader reader= new KeyboardReader();
      Random random = new Random();
      int choice=0;//menu
      int choice2=0;//which one to random
      int choice3=0;//which one to mult by
      int choice4=0;// how much to mult by
      int choice5=0;// row to reverse
      int choice6=0;// column to reverse
      int choice7=0;//matrix to resize
      int choice8=0;//row
      int choice9=0;//column
      int [] [] table1 = new int [3] [3];
      int [] [] table2 = new int [3] [3];
      int row1=3;//table1 rows
      int row2=3;//table2 rows
      int column1=3;//column1 rows
      int column2=3;//column2 rows
      do
      {


      System.out.println("Matrix time");
      System.out.println("\n\n1.Random values (0-10)");
      System.out.println("\n2.Multiply by X");
      System.out.println("\n3.Reverse the rows");
      System.out.println("\n4.Reverse the columns");
      System.out.println("\n5.Add the second to the first");
      System.out.println("\n6.Add the first to the second");
      System.out.println("\n7.Resize one of the matricies");
      System.out.println("\n8.View the matricies");
      System.out.println("\n9.Exit");
      choice=reader.readInt();

      if (choice==1)
      {
      System.out.println("Do you want to assign values to matrix 1 or 2");
      choice2=reader.readInt();

      if (choice2==1)
      {
      for (int r=0; r {
      for (int c=0; c {
      table1[r][c]=random.nextInt(10);
      }
      }
      }

      if (choice2==2)
      {
      for (int r=0; r {
      for (int c=0; c {
      table2[r][c]=random.nextInt(10);
      }
      }
      }

      }
      if (choice==2)
      {
      System.out.println("What number do you want to multiply by?");
      choice4=reader.readInt();
      System.out.println("Which matrix do you want to change");
      choice3=reader.readInt();

      if (choice3==1)
      {
      for(int r=0; r {
      for(int c=0; c {
      table1[r][c]=table1[r][c]*choice4;
      }
      }
      }

      if (choice3==2)
      {
      for(int r=0; r {
      for(int c=0; c {
      table2[r][c]=table2[r][c]*choice4;
      }
      }
      }
      }


      if (choice==3)
      {
      System.out.println("Which matrix's rows do you want to reverse?");
      choice5=reader.readInt();

      if(choice5==1)
      {
      for(int r=0; r {
      for (int c=0; c {
      table1[r][c]=table1[row1-r][c];
      }
      }
      }
      if(choice5==2)
      {
      for(int r=0; r {
      for (int c=0; c {
      table2[r][c]=table2[row2-r][c];
      }
      }
      }

      }
      if (choice==4)
      {
      System.out.println("Which matrix's columns do you want to reverse?");
      choice6=reader.readInt();

      if(choice6==1)
      {
      for(int r=0; r {
      for (int c=0; c {
      table1[r][c]=table1[r][column1-c];
      }
      }
      }
      if(choice6==2)
      {
      for(int r=0; r {
      for (int c=0; c {
      table2[r][c]=table2[r][column2-c];
      }
      }
      }
      }
      if (choice==5)
      {
      if (row1==row2 && column1==column2)
      {

      for (int r=0; r {
      for (int c=0;c {
      table1[r][c]=table2[r][c]+table1[r][c];
      }
      }
      }
      }
      if (choice==6)
      {
      if (row1==row2 && column1==column2)
      {

      for (int r=0; r {
      for (int c=0;c {
      table2[r][c]=table1[r][c]+table2[r][c];
      }
      }
      }
      }
      if (choice==7)
      {
      System.out.println("Which matrix do you want to resize?");
      choice7=reader.readInt();

      if(choice7==1)
      {
      System.out.println("What do you want the new row size to be?");
      choice8=reader.readInt();
      System.out.println("What do you want the new column size to be?");
      choice9=reader.readInt();
      int tabletemp[] [] = new int [row1] [column1];
      for (int r=0; r {
      for (int c=0;c {
      tabletemp[r][c]=table1[r][c];
      }
      }
      table1= new int [choice8][choice9];
      row1=choice8;
      column1=choice9;
      for (int r=0; r {
      for (int c=0; c {
      table1[r][c]=tabletemp[r][c];
      }
      }
      }
      if(choice7==2)
      {
      System.out.println("What do you want the new row size to be?");
      choice8=reader.readInt();
      System.out.println("What do you want the new column size to be?");
      choice9=reader.readInt();
      int tabletemp[] [] = new int [row2] [column2];
      for (int r=0; r {
      for (int c=0;c {
      tabletemp[r][c]=table2[r][c];
      }
      }
      table2= new int [choice8][choice9];
      row2=choice8;
      column2=choice9;
      for (int r=0; r {
      for (int c=0; c {
      table2[r][c]=tabletemp[r][c];
      }
      }
      }
      }
      if (choice==8)
      {
      System.out.println("\nTABLE1\n\n");
      for (int r=0; r {
      for (int c=0; c {
      System.out.println("\nRow : "+r+" Column :"+c+ " = "+table1[r][c]);
      }
      }
      System.out.println("\nTABLE2\n\n\n");
      for (int t=0; t {
      for (int c=0; c {
      System.out.println("\nRow : "+t+" Column :"+c+ " = "+table2[t][c]);
      }
      }

      }
      }while(choice!=9);
      }
      }

      Comment

      Working...
      X