473,473 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help! I can't make my form visible [form is the commented area in showProduct]

18 New Member
I created a [PRODUCT FORM] with no errors after compilation yet it is not visible. Can anyone help?
[Commented area of showProduct is where i tried to create the form]



Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.JFrame;
  5.  
  6. public class Bookshop extends JFrame implements ActionListener
  7. {
  8.  //JFrame product = new JFrame();
  9.  JTextField productIdText;
  10.  JTextField productNameText;
  11.  JTextField productCostText;
  12.  JTextField productyearOfPublicationText;
  13.  JTextField productpublishingHouseText;
  14.  
  15.  JButton submit;
  16.  Product [] productList = new Product [100];
  17.  int numberOfProduct = 0;
  18.  
  19.  
  20.      public void showProduct(int productId,String productName,double cost,int yearOfPublication,String publishingHouse)
  21.         {
  22. //            
  23. //            
  24. //                 //JFrame product = new JFrame("PRODUCT");
  25. //                 setSize(400,400);
  26. //                 setLayout(null);
  27. //                 
  28. //                 productIdText = new JTextField(5);
  29. //                 productIdText.setSize(80,30);
  30. //                 productIdText.setLocation(100,0);
  31. //                 
  32. //                 add(productIdText);
  33. //                 
  34. //                 productNameText = new JTextField(5);
  35. //                 productNameText.setSize(80,30);
  36. //                 productNameText.setLocation(101,30);
  37. //                 add(productNameText);
  38. //                 
  39. //                 productCostText = new JTextField(5);
  40. //                 productCostText.setSize(80,30);
  41. //                 productCostText.setLocation(131,31);
  42. //                 add(productCostText);
  43. //                 
  44. //                 productyearOfPublicationText = new JTextField(5);
  45. //                 productyearOfPublicationText.setSize(80,30);
  46. //                 productyearOfPublicationText.setLocation(161,61);
  47. //                 add(productyearOfPublicationText);
  48. //                 
  49. //                 productpublishingHouseText = new JTextField(5); 
  50. //                 productpublishingHouseText.setSize(80,30);
  51. //                 productpublishingHouseText.setLocation(191,91);
  52. //                 add(productpublishingHouseText);
  53. //                 
  54. //                 submit = new JButton("click");
  55. //                 submit.addActionListener(this);
  56. //                 add(submit);
  57. //                 //getContentPane().add(product);
  58. //             
  59. //                 setVisible(true);
  60. //             }   
  61.  
  62.     public void actionPerformed(ActionEvent e)
  63.     {
  64.             if(e.getSource() == submit)
  65.             {
  66.                 int id =  Integer.parseInt(productIdText.getText());
  67.                 String name = productNameText.getText();
  68.                 double cost = Double.parseDouble(productCostText.getText());
  69.                 int yearOfPublication = Integer.parseInt(productyearOfPublicationText.getText()); 
  70.                 String publishingHouse = productpublishingHouseText.getText();
  71.                 //System.out.println();
  72.                 //System.out.println();
  73.  
  74.  
  75.                 productList[numberOfProduct] = new Product(id,name,cost,yearOfPublication,publishingHouse);
  76.                 numberOfProduct++;
  77.             }
  78.  
  79.         }
  80.  
  81.     public static void main(String []args)
  82.         { 
  83.            new Bookshop();
  84.         }
  85.  
  86. class Product
  87. {
  88.    private int productId;
  89.    private String productName;
  90.    private double cost;
  91.    private int yearOfPublication;
  92.    private String publishingHouse;
  93.  
  94.  
  95.      public Product(int productId,String productName,double cost,int yearOfPublication,String publishingHouse)
  96.          {
  97.            this.productId = productId;
  98.            this.productName = productName;
  99.            this.cost = cost;
  100.            this.yearOfPublication = yearOfPublication;
  101.            this.publishingHouse = publishingHouse;
  102.  
  103.  
  104.         }
  105.  
  106.     public void setSize(int x,int y)
  107.         {
  108.         }
  109.  
  110.     public void setproductIdText(int productIdText)
  111.             {
  112.             }
  113.  
  114.     public void setproductNameText(String productNameText)
  115.             {
  116.             }
  117.  
  118.     public void setId(int productId)
  119.            {
  120.            }
  121.  
  122.     public int getproductId()
  123.        {
  124.            return productId;
  125.        }
  126.     public void setproductName(String productName)
  127.        {
  128.          this.productName = productName;
  129.        }
  130.  
  131.     public String getproductName()
  132.        {
  133.            return productName;
  134.        }
  135.  
  136.     public void setcost(double cost)
  137.        {
  138.          this.cost = cost;
  139.        }
  140.  
  141.     public double getcost()
  142.        {
  143.            return cost;
  144.        }
  145.  
  146.     public void setyearOfPublication(int yearOfPublication)
  147.        {
  148.          this.yearOfPublication = yearOfPublication;
  149.        }
  150.  
  151.     public int getyearOfPublication()
  152.        {
  153.            return yearOfPublication;
  154.        }
  155.  
  156.     public void setpublishingHouse(String publishingHouse)
  157.        {
  158.          this.publishingHouse = publishingHouse;
  159.        }
  160.  
  161.     public String getpublishingHouse()
  162.        {
  163.            return publishingHouse;
  164.        }
  165. }
  166.  
  167. class Book extends Product
  168. {
  169.  private String author;
  170.  private int isbn;
  171.  private int numberOfPages;
  172.  
  173.  
  174.     public Book(String author, int isbn, int numberOfPages, int productId, String productName, double cost,
  175.                            int yearOfPublication, String publishingHouse)
  176.         {
  177.          super(productId,productName,cost,yearOfPublication,publishingHouse);      
  178.          this.author = author;
  179.          this.isbn = isbn;
  180.          this.numberOfPages = numberOfPages; 
  181.         }
  182. }
  183.  
  184. class Software extends Product
  185. {
  186.  private int ram;
  187.  private int processor;
  188.  
  189.  
  190.  
  191.      public Software(int ram,int processor,int productId, String productName, double cost,
  192.                       int yearOfPublication, String publishingHouse)
  193.          {
  194.              super(productId,productName,cost,yearOfPublication,publishingHouse);      
  195.              this.ram = ram;
  196.              this.processor = processor; 
  197.          }
  198.  
  199. }
  200. }
  201.  
  202.  
I attached a picture copy of the form section. Thanks
Attached Files
File Type: docx BK.doc.docx (294.9 KB, 359 views)
Jul 19 '15 #1
1 1375
rajujrk
107 New Member
Hi,

Form is now Visible, Please make sure your components inside the JFrame are aligned. Its not aligned properly. Please find the below Code

Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.JFrame;
  6.  
  7. public class Bookshop extends JFrame implements ActionListener {
  8.     // JFrame product = new JFrame();
  9.     JTextField productIdText;
  10.     JTextField productNameText;
  11.     JTextField productCostText;
  12.     JTextField productyearOfPublicationText;
  13.     JTextField productpublishingHouseText;
  14.  
  15.     JButton submit;
  16.     Product[] productList = new Product[100];
  17.     int numberOfProduct = 0;
  18.  
  19.     public Bookshop() {
  20.  
  21.  
  22.          //JFrame product = new JFrame("PRODUCT");
  23.          setSize(400,400);
  24.          setLayout(null);
  25.  
  26.          productIdText = new JTextField(5);
  27.          productIdText.setSize(80,30);
  28.          productIdText.setLocation(100,0);
  29.  
  30.          add(productIdText);
  31.  
  32.          productNameText = new JTextField(5);
  33.          productNameText.setSize(80,30);
  34.          productNameText.setLocation(101,30);
  35.          add(productNameText);
  36.  
  37.          productCostText = new JTextField(5);
  38.          productCostText.setSize(80,30);
  39.          productCostText.setLocation(131,31);
  40.          add(productCostText);
  41.  
  42.          productyearOfPublicationText = new JTextField(5);
  43.          productyearOfPublicationText.setSize(80,30);
  44.          productyearOfPublicationText.setLocation(161,61);
  45.          add(productyearOfPublicationText);
  46.  
  47.          productpublishingHouseText = new JTextField(5);
  48.          productpublishingHouseText.setSize(80,30);
  49.          productpublishingHouseText.setLocation(191,91);
  50.          add(productpublishingHouseText);
  51.  
  52.          submit = new JButton("click");
  53.          submit.addActionListener(this);
  54.          add(submit);
  55.          //getContentPane().add(product);
  56.  
  57.          setVisible(true);
  58.     }
  59.  
  60.     public void actionPerformed(ActionEvent e) {
  61.         if (e.getSource() == submit) {
  62.             int id = Integer.parseInt(productIdText.getText());
  63.             String name = productNameText.getText();
  64.             double cost = Double.parseDouble(productCostText.getText());
  65.             int yearOfPublication = Integer
  66.                     .parseInt(productyearOfPublicationText.getText());
  67.             String publishingHouse = productpublishingHouseText.getText();
  68.             // System.out.println();
  69.             // System.out.println();
  70.  
  71.             productList[numberOfProduct] = new Product(id, name, cost,
  72.                     yearOfPublication, publishingHouse);
  73.             numberOfProduct++;
  74.         }
  75.  
  76.     }
  77.  
  78.     public static void main(String[] args) {
  79.         new Bookshop();
  80.     }
  81.  
  82.     class Product {
  83.         private int productId;
  84.         private String productName;
  85.         private double cost;
  86.         private int yearOfPublication;
  87.         private String publishingHouse;
  88.  
  89.         public Product(int productId, String productName, double cost,
  90.                 int yearOfPublication, String publishingHouse) {
  91.             this.productId = productId;
  92.             this.productName = productName;
  93.             this.cost = cost;
  94.             this.yearOfPublication = yearOfPublication;
  95.             this.publishingHouse = publishingHouse;
  96.  
  97.         }
  98.  
  99.         public void setSize(int x, int y) {
  100.         }
  101.  
  102.         public void setproductIdText(int productIdText) {
  103.         }
  104.  
  105.         public void setproductNameText(String productNameText) {
  106.         }
  107.  
  108.         public void setId(int productId) {
  109.         }
  110.  
  111.         public int getproductId() {
  112.             return productId;
  113.         }
  114.  
  115.         public void setproductName(String productName) {
  116.             this.productName = productName;
  117.         }
  118.  
  119.         public String getproductName() {
  120.             return productName;
  121.         }
  122.  
  123.         public void setcost(double cost) {
  124.             this.cost = cost;
  125.         }
  126.  
  127.         public double getcost() {
  128.             return cost;
  129.         }
  130.  
  131.         public void setyearOfPublication(int yearOfPublication) {
  132.             this.yearOfPublication = yearOfPublication;
  133.         }
  134.  
  135.         public int getyearOfPublication() {
  136.             return yearOfPublication;
  137.         }
  138.  
  139.         public void setpublishingHouse(String publishingHouse) {
  140.             this.publishingHouse = publishingHouse;
  141.         }
  142.  
  143.         public String getpublishingHouse() {
  144.             return publishingHouse;
  145.         }
  146.     }
  147.  
  148.     class Book extends Product {
  149.         private String author;
  150.         private int isbn;
  151.         private int numberOfPages;
  152.  
  153.         public Book(String author, int isbn, int numberOfPages, int productId,
  154.                 String productName, double cost, int yearOfPublication,
  155.                 String publishingHouse) {
  156.             super(productId, productName, cost, yearOfPublication,
  157.                     publishingHouse);
  158.             this.author = author;
  159.             this.isbn = isbn;
  160.             this.numberOfPages = numberOfPages;
  161.         }
  162.     }
  163.  
  164.     class Software extends Product {
  165.         private int ram;
  166.         private int processor;
  167.  
  168.         public Software(int ram, int processor, int productId,
  169.                 String productName, double cost, int yearOfPublication,
  170.                 String publishingHouse) {
  171.             super(productId, productName, cost, yearOfPublication,
  172.                     publishingHouse);
  173.             this.ram = ram;
  174.             this.processor = processor;
  175.         }
  176.  
  177.     }
  178. }
  179.  
  180.  
Thanks
Raju
Sep 25 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
6
by: vooose | last post by:
How would you determine if a window(Form) is visible. By visible I mean that you can currently see it, as apposed to Form.Visible. (which returns True when the window sits behind other windows) ...
1
by: abdul bari | last post by:
Hi I have a standard html form which is generated by an XSL sheet. The form data is submitted to the server and is passed on to file.aspx for processing. However file.aspx is refreshed every 5...
3
by: Shippy | last post by:
Please help, this is doing my head in!!!! I am sure it is something really simple and ovbious that I am missing but for the life of me I cant find where!!! I have this function... <script>...
5
by: | last post by:
How can i make my form invisible public class Form1 : System.Windows.Forms.Form static void Main() {
2
by: ConfusedMay | last post by:
I have a form that content all sales. Right now the default view is single form. the problem is that I can't view the form as a datasheet view when I run the form, even I already specified on the...
7
by: clloyd | last post by:
I have a form that opens with an embedded subform visible for data entry of new data only. The form is based of a select query so I can show data from multiple tables for verification but the sub...
2
Daniel B
by: Daniel B | last post by:
I would like to create a form, with a subform that shows data from several tables. Then I would like to be able to somehow click on one line of data, and it will take you to another form showing only...
2
by: lenniekuah | last post by:
Hi Good Guys, I have an interesting problem and I need your help. Please Help me. Requested were made by Businese Analyst to set the few Main FORMs VISIBLE PROPERTY TO FALSE when the POPUP FORM...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.