Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
| Search | Today's Posts | Mark Forums Read
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2012, 01:20 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default i cant align properly and resize the buttons help I'm a beginner at gui

//heres my code
//can anyone help me
//it has an error

import javax.swing.*; //components
import java.awt.*;//layout manager
import javax.swing.JButton.*;
public class Keyboard extends JFrame{
public static void main(String args[]){
new Keyboard(); // simply call the constructor
}
public Keyboard(){
setVisible(true);
setSize(1100,400);
setTitle("Keyboard");

JButton btnesc= new JButton("Esc");
JButton btnf1= new JButton("F1");
JButton btnf2= new JButton("F2");
JButton btnf3= new JButton("F3");
JButton btnf4= new JButton("F4");
JButton btnf5= new JButton("F5");
JButton btnf6= new JButton("F6");
JButton btnf7= new JButton("F7");
JButton btnf8= new JButton("F8");
JButton btnf9= new JButton("F9");
JButton btnf10= new JButton("F10");
JButton btnf11= new JButton("F11");
JButton btnf12= new JButton("F12");
JButton btnpause= new JButton("Pause");
JButton btnprt= new JButton("PRT SC");
JButton btndelete= new JButton("Delete");
JButton btninsert= new JButton("Insert");
JButton btnaccent= new JButton(" ` ");
JButton btn1= new JButton(" 1 ");
JButton btn2= new JButton(" 2 ");
JButton btn3= new JButton(" 3 ");
JButton btn4= new JButton(" 4 ");
JButton btn5= new JButton(" 5 ");
JButton btn6= new JButton(" 6 ");
JButton btn7= new JButton(" 7 ");
JButton btn8= new JButton(" 8 ");
JButton btn9= new JButton(" 9 ");
JButton btn0= new JButton(" 0 ");
JButton btnminus= new JButton(" - ");
JButton btnequal= new JButton(" = ");
JButton btnbackspace= new JButton(" BackSpace ");
JButton btnhome= new JButton(" Home ");
JButton btntab= new JButton(" Tab ");
JButton btnq= new JButton(" Q ");
JButton btnw= new JButton(" W ");
JButton btne= new JButton(" E ");
JButton btnr= new JButton(" R ");
JButton btnt= new JButton(" T ");
JButton btny= new JButton(" Y ");
JButton btnu= new JButton(" U ");
JButton btni= new JButton(" I ");
JButton btno= new JButton(" O ");
JButton btnp= new JButton(" P ");
JButton btnbracket= new JButton(" [ ");
JButton btnbracket2= new JButton(" ] ");
JButton btnbackslash= new JButton(" | ");
JButton btnpgup= new JButton(" PGUP ");
JButton btncaps= new JButton(" Caps Lock ");
JButton btna= new JButton(" A ");
btna.setPreferredSize(5,5);
JButton btns= new JButton(" S ");
JButton btnd= new JButton(" D ");
JButton btnf= new JButton(" F ");
JButton btng= new JButton(" G ");
JButton btnh= new JButton(" H ");
JButton btnj= new JButton(" J ");
JButton btnk= new JButton(" K ");
JButton btnl= new JButton(" L ");
JButton btnsemi= new JButton(" ; ");
JButton btnapo= new JButton(" ' ");
JButton btnenter= new JButton(" Enter ");
JButton btnpgdn= new JButton("PGDN");
JButton btnshift= new JButton(" Shift ");
JButton btnshift2= new JButton(" Shift ");
JButton btnz= new JButton(" Z ");
JButton btnx= new JButton(" X ");
JButton btnc= new JButton(" C ");
JButton btnv= new JButton(" V ");
JButton btnb= new JButton(" B ");
JButton btnn= new JButton(" N ");
JButton btnm= new JButton(" M ");
JButton btncomma= new JButton(",");
JButton btnperiod= new JButton(".");
JButton btnslash= new JButton("/");
JButton btnctrl= new JButton(" CTRL ");
JButton btnwin= new JButton(" Windows ");
JButton btnspace= new JButton(" ");
JButton btnalt= new JButton(" Alt ");
JButton btnalt2= new JButton(" Alt ");
JButton btnewan= new JButton(" [] ");
JButton btnfn= new JButton(" fn ");
JButton btnctrl2= new JButton(" CTRL ");
JButton btnup= new JButton("^");
JButton btnend= new JButton("End");
JButton btnleft= new JButton("<");
JButton btnright= new JButton(">");
JButton btndown= new JButton("v");

JPanel main=new JPanel();
main.setLayout(new GridLayout(4,1));

JPanel A=new JPanel();
A.setLayout(new GridLayout(2,1));

JPanel A1=new JPanel();
A1.setLayout(new FlowLayout());

A1.add(btnesc);
A1.add(btnf1);
A1.add(btnf2);
A1.add(btnf3);
A1.add(btnf4);
A1.add(btnf5);
A1.add(btnf6);
A1.add(btnf7);
A1.add(btnf8);
A1.add(btnf9);
A1.add(btnf10);
A1.add(btnf11);
A1.add(btnf12);
A1.add(btnpause);
A1.add(btnprt);
A1.add(btninsert);
A1.add(btndelete);
A.add(A1);

JPanel A2= new JPanel();
A2.setLayout(new FlowLayout());

JPanel A2c= new JPanel();
A2c.setLayout(new FlowLayout());

A2c.add(btnaccent);
A2.add(A2c);
A.add(A2);

JPanel A2d= new JPanel();
A2d.setLayout(new FlowLayout());

A2d.add(btn1);
A2.add(A2d);
A.add(A2);

JPanel A2e= new JPanel();
A2e.setLayout(new FlowLayout());

A2e.add(btn2);
A2.add(A2e);
A.add(A2);

JPanel A2p= new JPanel();
A2p.setLayout(new FlowLayout());

A2p.add(btn3);
A2.add(A2p);
A.add(A2);

JPanel A2f= new JPanel();
A2f.setLayout(new FlowLayout());

A2f.add(btn4);
A2.add(A2f);
A.add(A2);

JPanel A2g= new JPanel();
A2g.setLayout(new FlowLayout());

A2g.add(btn5);
A2.add(A2g);
A.add(A2);

JPanel A2h= new JPanel();
A2h.setLayout(new FlowLayout());

A2h.add(btn6);
A2.add(A2h);
A.add(A2);

JPanel A2i= new JPanel();
A2i.setLayout(new FlowLayout());

A2i.add(btn7);
A2.add(A2i);
A.add(A2);

JPanel A2j= new JPanel();
A2j.setLayout(new FlowLayout());

A2j.add(btn8);
A2.add(A2j);
A.add(A2);

JPanel A2k= new JPanel();
A2k.setLayout(new FlowLayout());

A2k.add(btn9);
A2.add(A2k);
A.add(A2);

JPanel A2o= new JPanel();
A2o.setLayout(new FlowLayout());

A2o.add(btn0);
A2.add(A2o);
A.add(A2);

JPanel A2m= new JPanel();
A2m.setLayout(new FlowLayout());

A2m.add(btnminus);
A2.add(A2m);
A.add(A2);

JPanel A2n= new JPanel();
A2n.setLayout(new FlowLayout());

A2n.add(btnequal);
A2.add(A2n);
A.add(A2);

JPanel A2l= new JPanel();
A2l.setLayout(new FlowLayout());

A2l.add(btnbackspace);
A2.add(A2l);
A.add(A2);

JPanel A2b= new JPanel();
A2b.setLayout(new FlowLayout());

A2b.add(btnhome);
A2.add(A2b);
A.add(A2);

main.add(A);

JPanel B= new JPanel();
B.setLayout(new GridLayout(2,1));

JPanel B1= new JPanel();
B1.setLayout(new FlowLayout());

JPanel B1a= new JPanel();
B1a.setLayout(new FlowLayout());

B1a.add(btntab);
B1.add(B1a);
B.add(B1);

JPanel B1b= new JPanel();
B1b.setLayout(new FlowLayout());

B1b.add(btnq);
B1.add(B1b);
B.add(B1);

JPanel B1c= new JPanel();
B1c.setLayout(new FlowLayout());

B1c.add(btnw);
B1.add(B1c);
B.add(B1);

JPanel B1d= new JPanel();
B1d.setLayout(new FlowLayout());

B1d.add(btne);
B1.add(B1d);
B.add(B1);

JPanel B1e= new JPanel();
B1e.setLayout(new FlowLayout());

B1e.add(btnr);
B1.add(B1e);
B.add(B1);

JPanel B1f= new JPanel();
B1f.setLayout(new FlowLayout());

B1f.add(btnt);
B1.add(B1f);
B.add(B1);

JPanel B1g= new JPanel();
B1g.setLayout(new FlowLayout());

B1g.add(btny);
B1.add(B1g);
B.add(B1);

JPanel B1h= new JPanel();
B1h.setLayout(new FlowLayout());

B1h.add(btnu);
B1.add(B1h);
B.add(B1);

JPanel B1i= new JPanel();
B1i.setLayout(new FlowLayout());

B1i.add(btni);
B1.add(B1i);
B.add(B1);

JPanel B1j= new JPanel();
B1j.setLayout(new FlowLayout());

B1j.add(btno);
B1.add(B1j);
B.add(B1);

JPanel B1k= new JPanel();
B1k.setLayout(new FlowLayout());

B1k.add(btnp);
B1.add(B1k);
B.add(B1);

JPanel B1l= new JPanel();
B1l.setLayout(new FlowLayout());

B1l.add(btnbracket);
B1.add(B1l);
B.add(B1);

JPanel B1m= new JPanel();
B1m.setLayout(new FlowLayout());

B1m.add(btnbracket2);
B1.add(B1m);
B.add(B1);

JPanel B1n= new JPanel();
B1n.setLayout(new FlowLayout());

B1n.add(btnbackslash);
B1.add(B1n);
B.add(B1);

JPanel B1o= new JPanel();
B1o.setLayout(new FlowLayout());

B1o.add(btnpgup);
B1.add(B1o);
B.add(B1);

B.add(B1);

JPanel B2= new JPanel();
B2.setLayout(new FlowLayout());

B2.add(btncaps);
B2.add(btna);
B2.add(btns);
B2.add(btnd);
B2.add(btnf);
B2.add(btng);
B2.add(btnh);
B2.add(btnj);
B2.add(btnk);
B2.add(btnl);
B2.add(btnsemi);
B2.add(btnapo);
B2.add(btnenter);
B2.add(btnpgdn);
B.add(B2);

main.add(B);

JPanel C= new JPanel();
C.setLayout(new FlowLayout());

JPanel C1= new JPanel();
C1.setLayout(new FlowLayout());

JPanel C1o= new JPanel();
C1o.setLayout(new GridLayout(2,1));

JPanel C1A = new JPanel();
C1A.setLayout(new GridLayout(0,1));
C1A.add(btnshift);
C1o.add(C1A);

JPanel C1q= new JPanel();
C1q.setLayout(new GridLayout(1,2));

JPanel C1B = new JPanel();
C1B.setLayout(new GridLayout(1,0));
C1B.add(btnctrl);
C1q.add(C1B);
C1o.add(C1q);

JPanel C1p = new JPanel();
C1p.setLayout(new GridLayout());
C1p.add(btnfn);
C1q.add(C1p);
C1o.add(C1q);
C1.add(C1o);

JPanel C1c= new JPanel();
C1c.setLayout(new GridLayout(2,2));

C1c.add(btnz);
C1c.add(btnx);
C1c.add(btnwin);
C1c.add(btnalt);
C1.add(C1c);

JPanel C1d=new JPanel();
C1d.setLayout(new GridLayout(2,1));

JPanel C1e=new JPanel();
C1e.setLayout(new GridLayout(1,5));

C1e.add(btnc);
C1e.add(btnv);
C1e.add(btnb);
C1e.add(btnn);
C1e.add(btnm);
C1.add(C1e);

JPanel C1f=new JPanel();
C1f.setLayout(new GridLayout(1,1));

C1f.add(btnspace);
C1.add(C1f);
C1.add(C1d);

JPanel C1g=new JPanel();
C1g.setLayout(new GridLayout(2,2));

C1g.add(btncomma);
C1g.add(btnperiod);
C1g.add(btnalt2);
C1g.add(btnewan);
C1.add(C1g);

JPanel C1h=new JPanel();
C1h.setLayout(new GridLayout(2,2));

JPanel C1i=new JPanel();
C1i.setLayout(new FlowLayout());

C1i.add(btnslash);
C1i.add(btnshift2);
C1h.add(C1i);

JPanel C1j=new JPanel();
C1j.setLayout(new FlowLayout());

C1j.add(btnctrl2);
C1j.add(btnleft);
C1h.add(C1j);

C1.add(C1h);

JPanel C1k=new JPanel();
C1k.setLayout(new GridLayout(2,2));

C1k.add(btnup);
C1k.add(btnend);
C1k.add(btndown);
C1k.add(btnright);
C1.add(C1k);

C.add(C1);

main.add(C);

add(main);

}

}




Similar Threads
Thread Thread Starter Forum Replies Last Post
Align to right not working Cyber Shiva HTML Code Clinic 4 July 19th, 2007 01:49 PM
EASY Q: Left-Align and Right-Align DIV? panuvin ASP.NET 1.0 and 1.1 Basics 0 December 16th, 2006 02:02 AM
align=right? larry Javascript How-To 11 July 6th, 2004 05:07 PM
Align text acko ASP.NET 1.x and 2.0 Application Design 2 January 9th, 2004 10:21 AM
align Center melvik C# 1 September 7th, 2003 04:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.