Layout Managers - Matrix Of Buttons At The Dimensions Of Panel
Oct 4, 2014
I have read the API and looked at examples but its not answering my question. Which layout would treat a panel as its own entity. Meaning if I made a method that made a matrix of buttons using GridLayout and returned that panel. Then called the method onto a frame and the buttons would not spread out all over the frame. They would simply stop at the dimensions of the panel. Am I looking for something that is not possible?
View Replies
ADVERTISEMENT
Dec 7, 2014
I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.
Below is where I create a matrix of buttons via Swing
public class View extends Mybuttons{
private static final long serialVersionUID = 1L;
JFrame frame;
JPanel matrixPanel, optionsPanel;
Mybuttons[][] matrixBtn;
Later in this class:
JPanel matrixPan(){
matrixBtn = new Mybuttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));
//creating a 25x25 matrix of buttons
[Code]...
In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).
private Mybuttons getUnvisitedChildNode(Mybuttons b){
//example of some of the things I have tried
int x= Mybuttons.getComponentAt(b);
int y= Mybuttons.indexOf(b);
int j=0;
return b;
}
[Code]...
View Replies
View Related
Nov 19, 2014
Is it possible to put Jlabels in to a grid Layout on a Panel in a Jinternal frame
View Replies
View Related
Dec 5, 2014
java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.
View Replies
View Related
Jun 1, 2014
I want to add only one button in a JFrame by using Mig Layout, dock south as BorderLayout.South does . Is it possible?
View Replies
View Related
Aug 27, 2014
I'm trying to fix the length of expenses to a appropriate size on my Jpanel but not sure how.
package mybudgetapp;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
[code]....
View Replies
View Related
Apr 1, 2014
When i click on the button from bottom panel, top panel need to be redrawn. But redrawing is not happening. It happens only when resizing the applet.
public class Graphics_Chart(){
public init(){
JScrollPane topPane = new JScrollPane(new ImagePanel2());
topPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
topPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
[code]...
View Replies
View Related
Apr 17, 2015
i have to use a if loop. I just started using methods and loops..You have been hired as a software developer for Canada’s customs - Toronto Pearson International Airport. Your job is to develop part of the Canada Passport System. The Database Administrator has forwarded to you the database for all the Canadians. For simplicity, assume you only have five records (i.e., only five people on file). These fixed records are the following:
First name, Last name, SIN, Last Date of Entry to Canada, Number of Entries
Mike beee 4567 12-12-1999 7
Jessie weree 4444 07-07-2007 1
Liza veee 2121 05-05-2013 2
Zico qeeee 2444 Never left the country 0
the two dimensional array stores all the values. In addition, all these values should be of type String.The Canadian officer can always see the following four choices:
1) Show custom’s database,
2)Update custom’s database,
3) A summary of a passenger’s record, and
4) Exit.
Choice 1 : always allows the officer to see all the database records (i.e., the five records). Each of these records consists of the following: First Name, Last Name, SIN, Last Date of Entry to Canada, and the Number of Entries (i.e., see the above stored values).
Choice 2 : allows the officer to update the database whenever one of the five Canadian passengers arrives. Once the officer chooses this option, the system will ask him/her for the SIN of the passenger. Then the system will ask for today’s date (i.e., the recent entry date). The system will then reflect those changes on the console screen and the number of entries will be increased by one.
Choice 3: summarizes the record for one passenger where his/her first and last names and last date of entry to Canada will be shown. The last date of entry should only have the last four digits (i.e., only the year). To extract those digits, you should use the String’s method(s). However,before a record is summarized, the records of all Canadians should be shown on the screen in order to allow the officer to choose among those records. Choice 4 allows the officer to exit from the system completely; otherwise the list of choices should be always shown on his/her monitor.This is the code i have so far.
import java.util.Scanner;
public class QuestionFive{
public static void main(String[] args) {
double passportInput;
Scanner sc = new Scanner(System.in);
// public static int generalList() // to show the list of choices and return the chosen option
//
// public static void updateRecords(int recordSize, String[][] passportDataBase) //to update the records
//
[code]....
View Replies
View Related
Apr 28, 2015
So in trying to create a circle class, and use the dimensions of that circle (radius, area, etc.) to prove it will equal pie and print (3.141592653589793). This is my code so far it and am getting an error in the last two classes. I know it has to do with Circle(Radius); in the 2nd class but whenever i call upon it, it is assigned to itself. And in the last class im not too sure how to put the B= new b(1,1).
[public class Circle {
private double radius;
public Circle() {
radius = 0;
}
public Circle(double radius) {
this.radius = radius;
[Code] .....
View Replies
View Related
Aug 3, 2014
I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9
6 1 2
5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*;
public class Spiral
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int n=Integer.parseInt(br.readLine());
[Code] .....
View Replies
View Related
Apr 5, 2014
I have two(panel1 and panel2) panels in a jframe,all three of them are different classes .
In jframe there is a display panel on which the panel1 and panel2 are called and displayed.
now i have a button in panel1 .i want that when i will click on that button panel2 will be displayed or added to the dispalypanel of jframe.
View Replies
View Related
Apr 24, 2014
Im trying to get the user to input the rows one by one but my input stops after the first. the examples i looked at in my book had this way i used as well. i are my rows and j are my columns. What is the correct way to do it?
import java.util.Scanner;
public class Exercise08_01 {
public static void main(String[] args) {
[Code]....
View Replies
View Related
Aug 1, 2014
Ok I am trying to at this point read in a matrix from a txt file in the format with order of the matrix leading the matrix. Like this :
1
5
2
2 3
5 9
3
3 -2 4
-1 5 2
-3 6 4
4
2 4 5 6
0 3 6 9
0 0 9 8
0 0 0 5
4
2 4 5 6
0 0 0 0
0 0 9 8
0 0 0 5
My code then is supposed to read it in and store it as an Array of singly linked lists. I am having trouble with my code, I am only getting outputs where it is only storing the first line of the txt matrixs like so:
5.0
2.0 3.0
2.0 3.0
3.0 -2.0 4.0
3.0 -2.0 4.0
3.0 -2.0 4.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
2.0 4.0 5.0 6.0
Is there something obvious in my code that is making it only save the first lines and how can i fix it.
//import java tools
import java.io.*;
import java.util.Scanner;
//Test.java
//See readMe.txt file for implementation instructions
//input: "input.txt"
[code]...
View Replies
View Related
Feb 28, 2014
why my code is not printing the matrix and sum?
The Java-program Matrix below first asks the user for the number of rows and columns in a matrix. After this the program asks for the values of the elements. Finally, program prints the elements of the matrix and their sum on screen. Your task is to create the missing methods. Check the example print to see how to modify the print. When printing the matrix, values on the same row are separated using tabulator.
Program to complete:
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");
[code]...
Write the missing methods here / Methods are written in the text box below.
Example output
Type in the number of rows: 3
Type in the number of columns: 4
Type in the element 1 of the row 1: 1
Type in the element 2 of the row 1: 2
Type in the element 3 of the row 1: 3
Type in the element 4 of the row 1: 4
Type in the element 1 of the row 2: 5
[code]...
Matrix:
1 2 3 4
5 6 7 8
9 10 11 12
Sum of the elements of the matrix: 78
my code
import java.util.Scanner;
public class apples {
public static void main(String[] args) {
int rows, columns;
Scanner reader = new Scanner(System.in);
System.out.print("Type in the number of rows: ");
[code]...
View Replies
View Related
Nov 16, 2014
I am making a Sudoku game and creating a matrix of JTextFields. However I am getting the following errors
Exception in thread "main" java.lang.NullPointerException
at SudokuView.board(SudokuView.java:30)
at SudokuView.<init>(SudokuView.java:18)
at SudokuMain.main(SudokuMain.java:5)
I know the problem is with this code
box[i][j] = new JTextField();
panel.add(box[i][j]);
I know this because when I do this:
panel.add(new JTextField());
It works. However it puzzles me why it is not working.
Whole Code:
import java.awt.GridLayout;
import javax.swing.*;
public class SudokuView {
JFrame frame;
JPanel panelBoard;
JTextField[][] box;
int row=10; int col=10;
SudokuView(){
frame = new JFrame("Play Sudoku GOOD LUCK");
[code]....
View Replies
View Related
Nov 21, 2014
I have a programming assignment in which I have to make a program which loads a crossword from a Properties file and then, when the user press a button, the program checks if the letters the user has typed in the interface are the same as in the correct matrix. If all the letters from a word are correct, the program must paint every letter of the word green.
I'm using two matrix, one that is called "mundo" (I 'm from Latin America) , which has the correct letter for each box. The other one is a JtextField matrix which ='ve created using a Gridllayout. I called this one crucigrama (crossword in Spanish)
This is the code I wrote to validate: So you can understand, here is a translation:
numero = number
fila = row
column = columna
bien - a boolean I used to check if the letter I've checked before are the same as the correct ones
.darLetra() - returns a string with the correct letter
[Code] .....
View Replies
View Related
Mar 8, 2014
I have string abcdef.I need to convert that string into 2 dimensional matrix.For each 2 characters in the string will be a matrix.For instance:
String: abcdef
Matrix will be: [a b],[c d],[e f]
How to do that in java?
View Replies
View Related
Jan 2, 2015
so I have this matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
View Replies
View Related
May 10, 2015
I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:
Methods:
Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix.
RandFill() - fills matrices with random numbers
addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix.
subMatrix() - subtracts both matrices
I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:
import java.util.*;
public class SquareMatrix2 {
public int size;
public int myMatrix [][];
public int myResultMatrix;
public int [][] ResultStatus;
[Code] ....
View Replies
View Related
Oct 11, 2014
i want solution to my program
View Replies
View Related
Oct 1, 2014
I'm new on Java/android and I wounder how could I get name of each control in a layout, ex.
for (int i=0;i<table1.getChildCount();i++ ) {
Object child=table1.getChildAt(i);
if( child instanceof EditText)
{
//get control name here
}
}
View Replies
View Related
May 12, 2014
I am using netbeans 7.2, glassfish 3.1.2, JSF 2.1 and Primefaces 3.2. When I add more than three menu tabs, I get this error ui layout initialization error the center-pane element does not exist the center-pane is a required element. This is my template.xhtml code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
[Code] ....
View Replies
View Related
Jun 2, 2014
I'm making a Pacman look-a-like game, now I'm making the map out of an 2D array (as a grid). I already initialized the 2d array spots with "0" and "1". I managed to do this but now I'm stuck.
I want to use the "0" and "1" to print the map. For example the "0" are grass and the "1" are walls. The map should be printed within a JFrame. And I would like to make the width and height 32x32 pixels.
I searched on the internet and i found a couple of example codes but non of it seems to work properly. This is the code I'm using to make the 2D array and initialize the spots.:
public class Level1 extends javax.swing.JFrame{
final int ROWS = 17;
final int COLS = 17;
int[][] field = new int[ROWS][COLS];
public Level1() {
initComponents();
setLocationRelativeTo(null);
[Code] .....
View Replies
View Related
May 4, 2014
So I'm doing a basic MVC layout for a pretty basic game that I am making in order to understand the whole MVC layout. The game requires the user to move up/down/left/right via JButtons on the GUI. Since I'm using an MVC layout and my buttons are in a different class than the ActionListeners, I was wondering what the best way to add the action listeners are?
Method 1:
View Class ActionListener method:
Java Code: public void addMovementListeners(ActionListener u, ActionListener d, ActionListener l, ActionListener r){
moveUp.addActionListener(u);
moveDown.addActionListener(d);
moveLeft.addActionListener(l);
moveRight.addActionListener(r);
[Code] ....
Which method is better? Is there another method that is even better than these two? Trying to get this MVC thing down.
View Replies
View Related
Jan 13, 2015
I am making a basic calculator using SWING.I want my JTextField to stretch across the top, above my buttons. All I can seem to get is it be the same size as one of my buttons.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
[code]...
View Replies
View Related
Mar 13, 2014
How to implement GridLayout. In my applet, I want to make a grid of 2 rows and 2 columns. In each grid I want to add a Label and a TextField. I want the background to be red.
So my code would be?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class GridLayoutApplet extends Applet implements ActionListener{
// construct components
Label fNameLabel = new Label("First Name");
TextField fNameField = new TextField(20);
[Code] .....
I have read about panels and frames but, it is all confusing to me. How can you add a label and a TextField to one square of the grid?
View Replies
View Related