Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.JOptionPane;
- import javax.swing.UIManager;
- import javax.swing.plaf.FontUIResource;
- public class TwoDArray
- {
- public static void changeJOP()
- {
- // These colors are very ugly to encourage YOU to CHANGE them!
- // The font of the message text
- UIManager.put("Label.font", new FontUIResource (new Font("Tempus Sans ITC", Font.BOLD, 58)));
- // The color of the message text
- UIManager.put("OptionPane.messageForeground",new Color(72,61,139));
- // color for text field (where you are inputting data)
- UIManager.put("TextField.background", Color.red);
- // font for message in text field
- UIManager.put("TextField.font", new FontUIResource(new Font("Dialog", Font.ITALIC, 24)));
- // color for message in text field
- UIManager.put("TextField.foreground", Color.yellow);
- // The color of the panel
- UIManager.put("Panel.background",Color.black);
- // The color around the outside of the panel
- UIManager.put("OptionPane.background",new Color(0,0,205));
- // Buttons at bottom
- UIManager.put("Button.background",new Color(132,112,255));
- UIManager.put("Button.foreground", new Color(72,61,139));
- UIManager.put("Button.font", new FontUIResource (new Font("Tempus Sans ITC", Font.BOLD, 14)));
- }
- public static void main(String[] args)
- {
- changeJOP();
- int rows=Integer.parseInt(JOptionPane.showInputDialog("How many rows do you want?"));
- int columns=Integer.parseInt(JOptionPane.showInputDialog("How many columns do you want?"));
- char[][]array=new char[rows][columns];
- fillRand(array);
- printArray(array);
- printRow(array);
- printColumn(array);
- }
- public static void fillRand(char array[][]){
- for(int i=0;i<array.length;i++) {
- for(int z=0;z<array[i].length;z++)
- array[i][z]=(char)(Math.random()*(224)+32);
- }
- }
- public static void printArray(char array[][]) {
- for(int i=0;i<array.length;i++) {
- for(int z=0;z<array[i].length;z++)
- System.out.print(array[i][z]);
- System.out.println("");
- }
- }
- public static void printRow(char array[][]) {
- int row=Integer.parseInt(JOptionPane.showInputDialog("What row do you want to print?"));
- for(int z=0;z<array[row-1].length;z++)
- System.out.print(array[row-1][z]);
- System.out.println("");
- }
- public static void printColumn(char array[][]) {
- int col=Integer.parseInt(JOptionPane.showInputDialog("What column do you want to print?"));
- for(int z=0;z<array.length;z++)
- System.out.print(array[z][col-1]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement