Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3.  
  4. import javax.swing.JOptionPane;
  5. import javax.swing.UIManager;
  6. import javax.swing.plaf.FontUIResource;
  7.  
  8. public class TwoDArray
  9. {
  10. public static void changeJOP()
  11. {
  12. // These colors are very ugly to encourage YOU to CHANGE them!
  13.  
  14. // The font of the message text
  15. UIManager.put("Label.font", new FontUIResource (new Font("Tempus Sans ITC", Font.BOLD, 58)));
  16. // The color of the message text
  17. UIManager.put("OptionPane.messageForeground",new Color(72,61,139));
  18.  
  19. // color for text field (where you are inputting data)
  20. UIManager.put("TextField.background", Color.red);
  21. // font for message in text field
  22. UIManager.put("TextField.font", new FontUIResource(new Font("Dialog", Font.ITALIC, 24)));
  23. // color for message in text field
  24. UIManager.put("TextField.foreground", Color.yellow);
  25.  
  26. // The color of the panel
  27. UIManager.put("Panel.background",Color.black);
  28. // The color around the outside of the panel
  29. UIManager.put("OptionPane.background",new Color(0,0,205));
  30.  
  31. // Buttons at bottom
  32. UIManager.put("Button.background",new Color(132,112,255));
  33. UIManager.put("Button.foreground", new Color(72,61,139));
  34. UIManager.put("Button.font", new FontUIResource (new Font("Tempus Sans ITC", Font.BOLD, 14)));
  35. }
  36. public static void main(String[] args)
  37. {
  38. changeJOP();
  39. int rows=Integer.parseInt(JOptionPane.showInputDialog("How many rows do you want?"));
  40. int columns=Integer.parseInt(JOptionPane.showInputDialog("How many columns do you want?"));
  41. char[][]array=new char[rows][columns];
  42. fillRand(array);
  43. printArray(array);
  44. printRow(array);
  45. printColumn(array);
  46. }
  47. public static void fillRand(char array[][]){
  48. for(int i=0;i<array.length;i++) {
  49. for(int z=0;z<array[i].length;z++)
  50. array[i][z]=(char)(Math.random()*(224)+32);
  51. }
  52. }
  53. public static void printArray(char array[][]) {
  54. for(int i=0;i<array.length;i++) {
  55. for(int z=0;z<array[i].length;z++)
  56. System.out.print(array[i][z]);
  57. System.out.println("");
  58. }
  59. }
  60. public static void printRow(char array[][]) {
  61. int row=Integer.parseInt(JOptionPane.showInputDialog("What row do you want to print?"));
  62. for(int z=0;z<array[row-1].length;z++)
  63. System.out.print(array[row-1][z]);
  64. System.out.println("");
  65. }
  66. public static void printColumn(char array[][]) {
  67. int col=Integer.parseInt(JOptionPane.showInputDialog("What column do you want to print?"));
  68. for(int z=0;z<array.length;z++)
  69. System.out.print(array[z][col-1]);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement