Tuesday, July 26, 2016

How to of the Day

How to of the Day


How to Close a Window in Java

Posted: 26 Jul 2016 05:00 PM PDT

This article will show you how to close a window in Java. Closing a window is much easier using Swing's JFrame, but it's also doable using AWT's Frame.

EditSteps

EditUsing javax.swing.JFrame

  1. Close window java step1.png
    Obtain an instance of a JFrame, or create a new one.
  2. Close window java step2_with_import.png
    Set default close operation. Default close operation is set using the setter method inside the JFrame class setDefaultCloseOperation that determines what happens when the close button is clicked and takes the following parameters:
    • WindowConstants.EXIT_ON_CLOSE - Closes the frame and terminates the execution of the program.
    • WindowConstants.DISPOSE_ON_CLOSE - Closes the frame and does not necessarily terminate the execution of the program.
    • WindowConstants.HIDE_ON_CLOSE - Makes the frame appear like it closed by setting its visibility property to false. The difference between HIDE_ON_CLOSE and DISPOSE_ON_CLOSE is that the latter releases all of the resources used by the frame and its components.
    • WindowConstants.DO_NOTHING_ON_CLOSE - Does nothing when the close button is pressed. Useful if you wish to, for example, display a confirmation dialog before the window is closed. You can do that by adding a WindowListener to the frame and overriding windowClosing method. Example of the custom close operation:
        frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);  frame.addWindowListener(new WindowAdapter() {          @Override          public void windowClosing(WindowEvent e) {                  // Ask for confirmation before terminating the program.                  int option = JOptionPane.showConfirmDialog(                          frame,                           "Are you sure you want to close the application?",                          "Close Confirmation",                           JOptionPane.YES_NO_OPTION,                           JOptionPane.QUESTION_MESSAGE);                  if (option == JOptionPane.YES_OPTION) {                          System.exit(0);                  }          }  });

EditUsing java.awt.Frame

  1. Close window java step1 method2.png
    Obtain an instance of a Frame, or create a new one.
  2. Close window java step2 method2.png
    Add window listener. Call addWindowListener method on the instance. The required argument is WindowListener. You can either implement every method of the WindowListener interface or override only the methods you need from WindowAdapter class.
  3. Close window java step3 method2.png
    Handle window closing event. Implement windowClosing method from WindowListener interface or override it from WindowAdapter class. There are two ways of closing a window:
    • Dispose the window after the close button is clicked:
      • Call dispose method inside windowClosing method.
      • frame.addWindowListener(new WindowAdapter() {          @Override          public void windowClosing(WindowEvent e) {                  // Dispose the window after the close button is clicked.                  dispose();          }  });
    • Terminate the program after the close button is clicked:
      • Call System.exit method inside windowClosing method.
      • frame.addWindowListener(new WindowAdapter() {          @Override          public void windowClosing(WindowEvent e) {                  // Terminate the program after the close button is clicked.                  System.exit(0);          }  });

EditTips

  • Swing is preferred over AWT since the latter is really outdated.
  • Using WindowAdapter you don't have to implement each and every method WindowListener contract tells us to, but only the ones we need.

EditRelated wikiHows


How to Kite Surf

Posted: 26 Jul 2016 09:00 AM PDT

Kite surfing is an exciting sport that combines a variety of skills. Contrary to popular belief, you don't have to be in crazy good shape to start learning.[1] Beginner kitesurfing requires a moderate level of physical fitness and endurance, and isn't for those who don't like adventure. But both men and women of all ages who love adventure and are close to the ocean should definitely give kite surfing a try![2]

EditSteps

EditChoosing Your Equipment

  1. Pick the right surf kite. You will want a beginner or training kite with high stability, a wide wind range, and moderate turning speed.[3] Beginner kites are usually smaller and advertised as such.[4] Maximum upwind drive is also important. [5] As you get more experienced you can feel free to pick a kite board that suits your individual style and needs.[6]
    Kite Surf Step 1 Version 3.jpg
    • Be sure to pick a kite that is appropriate for your bodyweight.[7] They should be clearly labeled.
    • Beginner kites are usually 2.5-3.5m from wingtip to wingtip.[8]
    • If you are unsure, ask a dive or surf shop employee.
  2. Select a kite surfing board. Choosing the right kite surfing board is essential. Every kite surfer is different, and you'll need to find one that is comfortable for you. Beginners will usually want larger, more stable boards. [9] Be sure to pick up a board that is advertised for your weight.[10]
    Kite Surf Step 2 Version 3.jpg
    • Your board shouldn't be too heavy. You should be able to carry it in one hand.
    • Make sure it has secure bindings to keep your feet connected to the board.
    • As you become more skilled you may want to get a board that has a handle so that you can learn to do tricks.
  3. Get together your safety equipment. In addition to having secure bindings on your board you will need safety equipment. You'll want a life jacket and a helmet at the very least, especially if you are a beginner. Be sure to also equip yourself with a safety or bypass leash so that you don't lose the kite if you lose your grip. [11]
    Kite Surf Step 3 Version 3.jpg
    • You may also want to wear a wetsuit, especially in cold water.
    • A secure bathing suit is necessary. A string bikini probably won't do.

EditLearning to Kite Surf on Land

  1. Inflate your kite. Before you can do anything you will need to put your kite together and get it in the air. Lay your kite on its back, connect it to the pump, and inflate it.[12]Setting up a surf kite for the first time isn't that hard, though it is easier if you have a experienced friend to help.

    • Tether your kite down while inflating, so it doesn't blow away.[13]
    • Learning on land can be done on the beach or even at a park.[14]
    • You don't necessarily need to be near the water for this.
  2. Launch your kite. Walk backwards, downwind towards the launch point, laying out your line cleanly behind you as you go.[15] Your partner should turn the kite over and stand with the kite ready to catch the wind. When you are ready, give your friend a signal to launch the kite. It should fly up and as high as possible, while being centered.[16]

  3. Practice flying. Get used to flying your kite on land. You should be in control of the kite at all times. Practice flying the kite at the right and the left without losing control to practice turning. The area in which you maintain control is called your wind window. Keep practicing until you get used to your specific kite's wind window. [17]

    • For most kites the window will be at approximately 11 o'clock on the left and 1 o'clock on the right.
    • If desired and if the area is clear, you can ride a skateboard while you practice flying your kite.[18]

EditMoving to the Water

  1. Get yourself wet. Once you are comfortable with the basic mechanics of the kite, it is time to get in the water. You'll do this without a board at first, and in wind conditions that are below 20 knots.[19] Be sure that you are in a relatively clear area of the water. You don't want anyone within 100 yards.[20] Practice the same flying exercises that you did while on land.

    • You will want to make sure that the area downwind of you is clear. That is probably where you will end up![21]
  2. Practice body dragging. Whilst the kite is in the air, practice dragging yourself back and forth using the wind through the water. You'll be "kite surfing" without a surf board. Do this until you are comfortable controlling your kite.This is essential to safety so make sure you are practiced with it before progressing further.[22]

    • You'll need to know how to do this if you ever have to retrieve a lost board.
  3. Get on your board. Whilst your kite is in the air, sit back in the water supported by your harness. Then put your feet onto the board and float to get used to the feeling. When ready, pull yourself up into a standing position. Keep your center of gravity low to maintain your balance before attempting to steer or surf.

    • Don't stand up too fast or aggressively - you might tip over the other way!
    • During the offseason you can practice your "board skills" on a skateboard.[23]
  4. Practice changing direction. Turning the kite will be harder now that you are on your board. Push the steering bar forward to bring the kite over your head. This will slow you down, allowing you to more easily move the kite to the other side of the wind window and start in the opposite direction.

  5. Practice practice practice. Rome wasn't built in a day, and kite surfing is a hobby that takes a long time to master. The more time you are on a board with a kite in the air, the more your skills will improve. Start slow at first and always stay safe.

EditVideo

EditRelated wikiHows

EditSources and Citations



Cite error: <ref> tags exist, but no <references/> tag was found


How to Take Care of Bamboo

Posted: 26 Jul 2016 01:00 AM PDT

Bamboo is an elegant plant that can add character to your landscape. It is a relatively hearty plant, and is able to withstand many different climates with just a little care and upkeep on your part. For the best results in your bamboo plants, you'll need to cultivate a bamboo-friendly environment, nurture your plants with the right nutrients, and troubleshoot problems that arise while growing.

EditSteps

EditCultivating a Healthy Environment

  1. Differentiate running and clumping bamboo. These are the two main varieties of bamboo. Many of the procedures you'll use to care for your running or clumping plants will be interchangeable among these two plants, but there are some differences you may want to take into account for aesthetic purposes.
    Take Care of Bamboo Step 1 Version 2.jpg
    • Running bamboo has thick canes spaced at regular intervals, much like the stereotypical image of bamboo. Clumping bamboo has thinner canes, a bush-like appearance, and its canes appear to sprout from the same, or nearly the same, location in the ground.
    • Running bamboo makes for a better screen when planted. Unlike clumping bamboo, which has drooping top segments and a narrow base, runners naturally form a screen with straight, vertical stalks.[1]
  2. Provide bright, indirect sunlight. If you have already planted your bamboo in an area that receives a lot of direct sunlight, you may want to string up a cloth between bean poles or stakes to offer some shade to the plants. Bamboo naturally grows in areas with partial shade, and giving this to your plants will encourage healthy growth.[2]
    Take Care of Bamboo Step 2 Version 2.jpg
  3. Add mulch to the soil around your bamboo. Mulch will help protect the roots of your bamboo from sudden changes in weather, like cold snaps.[3] It will also soak up water for the plant during dry periods. Additionally, it will deter weeds from encroaching on your bamboo plants.
    Take Care of Bamboo Step 3 Version 2.jpg
    • Spread your mulch carefully around young stalks and newly emerging bamboo. Too much mulch can damage the plant or make it difficult to grow.
    • You can spread mulch freely around the stalks of heartier, more established plants. Leave about an inch (2.5 cm) of free space around your stalks so the roots receive enough airflow.[4]
  4. Trim your shoots. You won't likely need to trim your bamboo until it has grown for a few years and filled in with leaves. Trimming will help your other plants receive more adequate sunlight. This will also remove growths that are unsightly or less healthy, encouraging the overall health and appearance of your plant.
    Take Care of Bamboo Step 4.jpg
    • When trimming, you should prioritize branches that look dead, sick, or weak. Most bamboo can be pruned without fear of harming the plant, so you should trim freely to achieve the look you desire in your bamboo.[5]
  5. Control the root growth of running bamboo. The roots of your running bamboo can easily grow out of control if you're not careful. If your bamboo is growing in an open area, this might not be a problem, however you can easily prevent the roots of your running bamboo from becoming invasive by trimming the roots.
    Take Care of Bamboo Step 5.jpg
    • Set a boundary for the roots of your bamboo plant and then dig a narrow trench on that boundary about 1 foot (.3 m) deep. Trim or sever any roots that you find in this trench, and check it regularly for new root growths.
    • Trimming the roots of your running bamboo will not harm the plant. These roots can usually be found roughly 5 inches (12.7 cm) deep in the soil.[6]

EditNurturing Your Bamboo

  1. Water your bamboo according to season. The most active season for bamboo growth is spring, so you should begin watering in late winter or early spring. Watering should be done on a weekly basis, and you should continue this watering schedule throughout the summer months.[7]
    Take Care of Bamboo Step 6.jpg
  2. Water with moderation. If you are growing your bamboo in loamy soil that drains well, you won't likely have issues with watering. Even so, the best environment for your bamboo to grow in will be moist, without being saturated or dry.[8]
    Take Care of Bamboo Step 7.jpg
    • You'll be able to tell if your bamboo is not receiving enough water by the curl of its leaves. If you notice leaf curl, continue your watering schedule, adding water in small increments until the leaves relax.
    • Some types of bamboo will also suffer from leaf curl in overly sunny environments. If you add water to your routine and notice no difference in the leaf curl, this could be an indication your plants are getting too much sun.[9]
  3. Maintain the water level of submerged bamboo. For plants that are grown in water, you'll want to make sure that the water level completely covers the roots of your plants and maintains a depth of a few inches (5 - 7 cm). To prevent disease, algae growth, and other issues that arise from stagnant water, you should drain and refill the water of your bamboo every few weeks.[10]
    Take Care of Bamboo Step 8.jpg
  4. Fertilize your bamboo. Fertilizing your bamboo will guarantee it has the nutrients it needs to grow healthy and strong. Fertilizing is especially important if your soil is low in phosphorous, nitrogen, or potassium. These three substances are vital for healthy, strong bamboo.[11]
    Take Care of Bamboo Step 9.jpg
    • You should add fertilizer to the soil surrounding your bamboo in early spring or late winter. This will ensure your plants have the nutrients needed for spring, which is the most active time for bamboo growth.
    • If your soil is poor in phosphorous, nitrogen, or potassium, you may need to add small amount of fertilizer periodically throughout the year. You should avoid fertilizing the area around your plants in winter.
    • Bamboo grown in water will need to be fertilized every few months with a water soluble plant fertilizer. You may want to coordinate your water changing cycles with your fertilizing.[12]
    • You might want to consider using grass/lawn fertilizer for your bamboo plants. This will be widely available at home and gardening stores, and will provide your bamboo with the food it needs.[13]

EditTroubleshooting Bamboo Problems

  1. Notice root rot when it occurs. Root rot can happen if you use too much fertilizer or water your plants excessively. You can tell when a plant has root rot by the brown, soft quality at the base of the stalks. When you see this in your plants, cut off the healthy tips and replant these elsewhere.[14]
    Take Care of Bamboo Step 10.jpg
    • When cutting the healthy parts of your bamboo, try to include two or three leaf-nodes per section. These nodes can be found by looking for a thickening of the stalk. In some cases, these will have offshoots.
    • Be sure to moderate your watering and fertilizing after this! Root rotted plants can be salvaged, but by moderating your plant care, you can avoid this entirely.[15]
  2. Cleanse mites from your plants. These kinds of bugs won't be a problem for your bamboo plants too often, but if you notice a white substance on the stalks of your plants that is sticky, cottony, web-like material, or irregular growths that are shaped like a snail, you may have scale or spider mites![16]
    Take Care of Bamboo Step 11.jpg
    • If your bamboo is in a container, you'll need to clean it out with a mild soap. If your potted bamboo is growing in pebbles, wash these in the same fashion. If you're using soil, this should be replaced.
    • Wipe down each of your plants using a rag dampened with soapy water. A few drops of dish detergent should do the trick. Be gentle while wiping to prevent damage to the stalk, and rinse the plant completely when you are finished.[17]
  3. Remedy brown tipped leaves. One of the most common causes of this is fluoride burn, which can especially be a problem if you live in an urban environment. The fluoride added to your water supply can cause the tips of your bamboo leaves to turn brown, though this can also be an indication that the air is too dry for your plants.[18]
    Take Care of Bamboo Step 12.jpg
    • Use distilled water or collected rainwater for your plants for cases of fluoride burn. You might leave a bucket or kiddie pool outside to catch rainwater, or you could build a rainwater collection system.
    • Dry air can be an issue for your bamboo if you live in an arid or semi-arid region. However, you can restore your bamboo leaves in the dryness by misting your plants daily or every few days in semi-arid climates.[19]

EditWarnings

  • Some types of bamboo can be highly invasive in certain climates. Consider reading up on bamboo before planting if you think this might be a problem for you.

EditThings You'll Need

  • Bamboo plant
  • Mulch
  • Nitrogen rich fertilizer
  • Pruning sheer
  • Shovel (for root trimming)
  • Water

EditRelated wikiHows

EditSources and Citations


Cite error: <ref> tags exist, but no <references/> tag was found


1 comment:

  1. Awesome!! You have the best article on this topic. You're doing a great job. Thanks for sharing.

    Cheers,
    http://www.flowerbrackets.com/how-to-find-length-of-a-string-in-java/

    ReplyDelete