Pros & cons of extending jframe or adding it

Hi i've written a class code that extends jframe (and is my main code for the application) now i see that many code examples (such as the divelog.java posted on java.sun) prefer adding a jframe to the class and .pack & .setvisible
beside code comfort (either way) is there a real reason to prefer one way over the other ?
thanks .

yes. always favour composition over inheritance. class inheritance is one of the most abused features of the language, I have to struggle with inappropriate use of it on a daily basis because we've got a team of morons who think it's ok to extend a class twelve times, just to change the order in which some buttons get displayed on-screen. that's not an exaggeration, at all
extend classes when the subclass really is an extension of the superclass, really is a kind-of JFrame or whatever. not just to re-use some methods and save some typing. hint: JFrame is a Container,which means it was intended to contain other UI objects. thus, by adding widgets to it, you are making use of it as intended, not making a new kind of JFrame

Similar Messages

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Pros & Cons of Using SAP PI Interfaces for Report Generation

    Hi Guru's
    I have a Scenario's like
    I have to generate a customized report in SAP with the main data's available in SAP ECC and some required data available in the Legacy System.
    I want to know the Pros & cons of using SAP PI RFC/Proxy adapter interface to get the data from the legacy system for each time the user execute the report in SAP ECC.
    Thanks in Advance

    There are couple of "dimensions" to consider in your PI interface design. For exemple when you are running the sizing exercise (Since we are considering adding a net new interface), you will need to capture specific information about new interface.i.e. S/A, adapters, frequency, avg payload size. etc..Note that the last two attributes will be hard to size properly in this case since you can't predict how frequent the end user will run the report which will impact the latency time required to pull the data. Latency will affect the user experience as visible side affect and definitely the SLA for other interfaces running at the same time.
    On the other hand, the data you are trying to retrieve from the legacy won't be used for transactional purpose but for the end user to pull KPIs from the system which can affect ECC as well. You may end up doing lot hot fixes for your report (Assuming that the report is a medium complexity code)
    There are other factors to consider but let's consider these are the major one.
    Cheers,
    F

  • Pros/Cons of replicating to files versus staging tables

    I am new to GoldenGate and am trying to figure out pros/cons of replicating to flatfiles to be processed by an ETL tool versus replicating directly to staging tables. We are using GoldenGate to source data from multiple transaction systems to flatfiles and then using Informatica to load thousands of flatfiles to our ODS staging. Trying to figure out if it would be better just to push data directly to staging tables. I am not sure which is better in terms of recovery, reconcilliation, etc. Any advice or thoughts on this would be appreciated.

    Hi,
    My Suggestion would be to push the data from multiple source systems directly to staging table and then populate target system using ELT tool like ODI.
    Oracle Data Integrator can be combined with Oracle Golden Gate (OGG) , that provides a cross-platform data replication and changed data capture. Oracle Golden Gate worked in a similar way to Oracle’s asynchronous change data capture but handles greater volumes and works across multiple database platforms.
    Source -> Staging -> Target
    ODI-EE supports all leading data warehousing platforms, including Oracle Database, Teradata, Netezza, and IBM DB2. This is complemented by the Oracle GoldenGate architecture, which decouples source and target systems, enabling heterogeneity of databases as well as operating systems and hardware platforms. Oracle GoldenGate supports a wide range of database versions for Oracle Database, SQL Server, DB2 z/Series and LUW, Sybase ASE, Enscribe, SQL/MP and SQL/MX, Teradata running on Linux, Solaris, UNIX, Windows, and HP NonStop platforms as well as many data warehousing appliances including Oracle Exadata, Teradata, Netezza, and Greenplum. Companies can quickly and easily involve new or different database sources and target systems to their configurations by simply adding new Capture and Delivery processes.
    ODI-EE and Oracle GoldenGate combined enable you to rapidly move transactional data between enterprise systems:
    Real-time data. - Immediately capture, transform, and deliver transactional data to other systems with subsecond latency. Improve organizational decision-making through enterprise-wide visibility into accurate, up-to-date information.
    Heterogeneous. - Utilize heterogeneous databases, packaged or even custom applications to leverage existing IT infrastructure. Use Knowledge Modules to speed the time of implementation.
    Reliability. - Deliver all committed records to the target, even in the event of network outages. Move data without requiring system interruption or batch windows. Ensure data consistency and referential integrity across multiple masters, back-up systems, and reporting databases.
    High performance with low impact. - Move thousands of transactions per second with negligible impact on source and target systems. Transform data at high performance and efficiency using E-LT. Access critical information in real time without bogging down production systems.
    Please refer to below links for more information on configuration of ODI-OGG.
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/odi/odi_11g/odi_gg_integration/odi_gg_integration.htm
    http://www.biblogs.com/2010/03/22/configuring-odi-10136-to-use-oracle-golden-gate-for-changed-data-capture/
    Hope this information helps.
    Thanks & Regards
    SK

  • Pro/cons to have indexes on its own tablspace

    hi ,
    i have a new db running on oracle 10G R2 , various table spaces have been created that can be extended from 8M , 2M , 128K
    my dba recommends that large insertion/updates tables goes to the 8M tablespace , but i notice that the indexes of those tables are in the same tablespace
    ques :
    1. can index exists on its own tablespace
    2 . are there pro/cons of having indexes in its own tablspace ?
    tks & rgds

    Not really the proper forum for this question. You should have rather posted the question to the [url http://forums.oracle.com/forums/forum.jspa?forumID=61]Database Forum
    > 1. can index exists on its own tablespace
    Yes.
    > 2 . are there pro/cons of having indexes in its own tablspace ?
    Maybe.. it depends entirely on what your requirements are, and the nature of the data and hardware.
    One reason to place indexes in a separate tablespace is simply for space management. E.g. this prevents some idiot developer of eating up all the space for tables, by indexing each and every column in a table and swamping the tablespaces with indexes.
    Another reason is block sizes. Tablespaces can each have a different block sizes. You may want to use large 128KB blocks for data and smaller 32KB blocks for indexes.
    That all said - personally I tend these days to prefer a single tablespace per logical database/application. In the past (especially back in Oracle 7) I always separated indexes and tables. But Oracle space management has improved so much, and we're dealing with such large data volumes these days, I do not think it is warranted without some sound technical reason to split data and indexes.

  • How can I use firefox with pro con latte extention on a linux OS that runs via a USB?

    What linux distro to use?
    What version of firefox to use? (Since it has to be compatible with pro con latte)

    Firefox tarballs from Mozilla Org use prefs within Firefox for updates. The "toggle" for not automatically updating - '''app.update.enabled''' and where to look for updates - '''app.update.url'''. The first needs to be '''''false''''' and the second could be a '''''null''''' string, do an update can't be found.
    ''I use both prefs to keep Firefox from updating by itself. I install each new version of Firefox as it is released, and keep the older versions around for reference purposes. Those prefs are the same since Firefox 1.5 came out.''
    The versions of Firefox that are part of an operating system installation usually are that OS's own build of Firefox, and don't use the same update setup as Mozilla uses, in most cases. I am not familiar with Cent OS, but Ubuntu and Debian look for Firefox updates and from their own program repository servers outside of Firefox - as with the tarballs from Mozilla.

  • How can you get the filter off if you can't remember the password? It's"pro con" and it wont even let me check out the rates for aflight.

    How can you get the filter off if you can't remember the password? It's"pro con" and it wont even let me check out the rates for aflight.

    You can check the file prefs.js in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder] and remove the line(s) related to that extension (procon.password).

  • Is there anything available that covers the pros/cons of a simple and network PCD migration?

    Is there anything available that covers the pros/cons of a simple and network PCD migration?  

    Hi,
    as such there is no DOC but I can share my views:
    Under Pros:
    a. PCD is an application use to migrate older versions[6.1.5, 7.x , 8.x] running on MCS to VM servers.
    b.It can be used to change the IP address or hostname on new servers without affecting existing version .
    c. Many users using MCS Hardware are not willing to migrate to latest version because of existing HW not supporting interim releases which they have to hop through to get on to the target release.
    d. Further, this requires license re-hosting as well for interim releases and major downtimes as well which can be avoided by using PCD without disturbing existing setup.
    e. Also, DRAM/HDD sizing needs to be considered while doing migration on MCS.PCD addresses these issues for migration.
    Under CONS:
    a. It needs to be ordered through Product Upgrade Tool and bootable is not downloadable from Cisco site.
    b. You could face some issues while doing migration which could be bugs but can be resolved.
    c.could face issues while discovering  cluster/doing migration but can be resolved.
    regds,
    aman

  • Decorate window of class extending JFrame

    Hello,
    I have a class that extends JFrame and I'd like to set it's look decorated the same way that it does when a new JFrame is built inside the code. Currently it's got the regular Java look (if I create a JFrame somewhere in the code it has the look I want), the following code didn't help, it only sets the subsequently created JFrames decorated:
        GUI frame = new GUI(); //GUI extends JFrame
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        frame.setDefaultLookAndFeelDecorated(true);

    Thanks for your reply. I already read that, in fact the section "Programmatically Setting the Look and Feel " instructs to write the code I posted on the previous post. I also tried:
    UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    SwingUtilities.updateComponentTreeUI(this);And it didn't work. The main frame has the regular LNF and subsequently created JFrames will have the javax.swing.plaf.metal.MetalLookAndFeel
    Also, after the code I posted on my previous post, GUI.isDefaultLookAndFeelDecorated() returns true.
    Thanx in advance! :)

  • What are pros/cons of using xmarks vs. firefox sync?

    Used Firefox for a long while. Bookmarks morphed to Xmarks, which in turn has been acquired twice. I continue to use the newer Xmarks. In process of setting up a new computer, found that Firefox has it's own bookmarks sync.
    Like to keep things as simple as possible. Does Firefox sync do all that Xmarks does? What are pros/cons of using xmarks vs. firefox sync?

    I am not in a business environment, just my home. So, I don't know your specific requirements. I operate a dual G5 xserve, a dual quad-core mac pro, 6+ Apple MacOSX computers of varying types and several other linux servers plus a couple of Windows machines. If it were me, I would get two mac pro's running MacOSX Server and use one for backup of the other. The xserve RAID is too expensive from my point of view. I copy data from the xserve to several MacOSX computers with firewire drives for my backup and I have every computer on a ups. (I am assuming that they will not all fail at once!
    I run Tiger servers and would suggest that you significantly test Leopard before committing to it.
    Hope that helps.

  • Which is better? Extend JFrame or Wrap it in a class???

    Just a random thought, have been programming swing for a long time now and during the time have been researhed a lot of swing examples on web and found out that most people tend to make a class extend JFrame in order to use it stuff.
    However the way i've been programming is to wrap it around a class by creating an instance of JFrame inside my class. In that way i feel is more easier to program.
    But which is better style of programming and which is better programming technique in terms of robustness, reusablitity & good general programming practice?

    The usual answer, it depends. If you don't want to change a JFrame's behaviour, you wrap it. If the JFrame class is lacking a feature you need, you extend it and implement the desired feature.

  • MacBook Pro name is being changed by adding ()

    MacBook Pro name is being changed by adding () after the name and incrementally increasing the number in (). I am using Yosemite.  I cannot determine what causes the number to be increased, but I am at 13 after resetting it this morning. This prevents my iOS devices from syncing wirelessly as they are looking for a different name.  I have reset the name several times and this continues to occur.
    I first noticed this issue during the Yosemite beta and reported it as an issue.
    Has anyone else experienced this issue and found a solution?

    I had this happen also. I reset my router and the problem stopped.
    regards

  • Pros / Cons of Running APEX on separate server

    Seeking feedback/thoughts on this general question.
    I am maintaining an APEX application that utilizes multiple schemas all residing in the same database as APEX. I am wondering what might be the pros / cons of putting APEX in a separate database and server.
    Would this necessarily yield security or performance benefits (or costs)?
    How many changes would need to be made in the APEX configuration and code? I have read here in the forum that at a minimum database links would need to be created to the utilized schemas on the other server, with appropriate grants. What else?
    Thanks.

    Please help us by putting your first name into your profile. Thanks.
    So what you want to do is have your application (and Application Express) access tables in a remote database. Yes, you can do that and database links are required.
    This almost always has negative performance impact and sometimes results in things not working due to database version differences, especially with down-level Oracle versions.
    It also makes application development more difficult if the Application Builder doesn't have local access to application parsing schemas. You can work around most of these problems by creating local views of remote tables, but I don't think 100% of the wizards and some SQL Workshop functionality are amenable to remote schema access. So I don't recommend it. What is your motivation to do this?
    By the way, "servers" don't matter in this discussion, it's all about databases.
    Scott

  • Pros & Cons for consuming web services in ABAP using ABAP PROXY

    Hi,
    Other then performence  is there any other disadvantages like security,etc for consuming web services in ABAP using ABAP proxy?
    I really appreciate if some one provide the more details(Pros & Cons ) regarding cosuming web services and I also want to know is there any other way to consume web services in ABAP.
    Thanks.

    <i> is there any other way to consume web services in ABAP</i>
    you can use cl_http_client class to make your program to act as http client and post the soap message too webservice. This way you dont need to generate proxy, but you should know the soap message format.
    Regards
    Raja

  • There are multiple MAC's in my house and I am considering buying Time Capsule to use as a file sharing device. Is anyone doing this? Pros/Cons?

    I have multiple MAC's in my house. I would like to create a file server environmet. I am considering using Time Capsule. Is anyone doing this? Pros/Cons?

    The Linksys should be about as fast as the Time Capsule. So you might as well connect the Time Capsule to the Linksys, disable sharing and wireless.
    Solution two is to use the TC as the router, wireless and network drive. This would save the power the Linksys needs. What is the Linksys connected to? a separate modem?

Maybe you are looking for

  • Saving layers within a folder to separate pdf's (complete n00bie warning)

    I have designed a set of wedding invites recently and when it came time to export I was wanting to find a smarter (and hopefully faster) way to export each individual invite. I have the document setup so one folder is all the artwork including detail

  • How can i print data in bi publisher template across wise

    Hi, Please let me know how can i print data in bi publisher template across wise. eg. In my C1 field there is a data coming like S JR MR i want to print this filed S JR MR Thanx Arjun

  • [JS][CS4-5] Apply hyperlink to xml tagged object

    Hi, Can anyone please help me? I'm strugling with this problem for days.... I'm trying to apply a new hyperlink to a xml tagged object (piece of text, frame or image)... The script trows an error "wrong source. Expected text but received XML element"

  • PDF-Email- spool

    i have a spool generated whicn needs to be converted into PDF file format and Excel file format. Both the files PDF and Excel having the data from spool should be sent as attachment in an email. Is ther any function modules which can handle this scen

  • Generic Exception with Extension Problem

    Consider the following .java files: public interface IRNode public <Return, Input, ExceptionType extends Exception> Return execute (IRNamedNodeAlgo<Return,Input,ExceptionType> algo, Input... input) throws ExceptionType; public interface IRNamedNodeAl