This document discusses graphical user interfaces in Java. It covers using layout managers like BorderLayout and GridLayout to position components in containers. Common components like text fields, text areas, radio buttons, check boxes, and menus are described. Handling user input through action listeners is also covered. The document provides examples of creating a GUI with menus to change the font style of sample text.
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdfoptokunal1
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, and creates a border around it
containing the title \"this is a JPanel.\"
2) Write a keyPressed method that behaves as follows. If the user presses the up arrow, the
method should output \"You pressed up\"using the System.out.printin method. Ifthe user presses
the down arrow, the method should output \"You pressed down\" using the System.out.printin
method.
3) Write a short class that represents a panelwith a single radio button that has the option
\"Yes\"and the option \"No.\" Bydefault, the Yes buttonshould be checked.
4) Suppose we have created a class called MyGUI, which represents a GUI. Write a programthat
creates a JFrame object, adds a MyGUI object to the frame and makes it visible.
5) Write a short class that represents a panelwith a single sliderthat has values from 0 to 250,
with largetick marks in incrementsof 50 and smalltick marks in increments of 10.
Solution
1)
/**
* The java Demo1 that cretes a titled border
* for jpanel.
* */
//Demo1.java
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class Demo1
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
//Create an instance of Jpanel
JPanel p1=new JPanel();
//Create an instance of TitledBorder
TitledBorder border = new TitledBorder(\"this is a JPanel\");
border.setTitleJustification(TitledBorder.CENTER);
//add border to panel ,p1
p1.setBorder(border);
//add panle to frame
frame.add(p1);
frame.setSize(250, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
2)
/**
* The java Demo2 that display a message
* for arrow up is pressed and arrow down
* key is pressed
*
* */
//Demo1.java
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class Demo2
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
//Create an instance of Jpanel
JPanel p1=new JPanel();
//Create an instance of TitledBorder
TitledBorder border = new TitledBorder(\"this is a JPanel\");
border.setTitleJustification(TitledBorder.CENTER);
//add border to panel ,p1
p1.setBorder(border);
p1.setFocusable(true);
//Add a KeyListener interface to the panel,p1
p1.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
/*Write to display pressed up
and pressed down */
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch( keyCode )
{
case KeyEvent.VK_UP:
System.out.println(\"You pressed up\");
break;
case KeyEvent.VK_DOWN:
System.out.println(\"You pressed down\");
break;
}
}
});
//add panle to frame
frame.add(p1);
frame.setSize(250, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
3)
/**
* the java program that deomons.
Gui programming a review - mixed contentYogesh Kumar
Class 12 IP Chapter 3 PPt, Mixed content ppt, GUI Programming - A review at a glance, (62 Slides, 5 MB), Homework_Ch3_PPT for school, Easy to understand, JAVA Basics PPt
import java.awt.Color;
import java.awt.Insets;
import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
/*
*Class Steganography_View
*/
public class Steganography_View extends JFrame
{
//size variables for window
private static int WIDTH = 500;
private static int HEIGHT = 400;
//elements for JPanel
private JTextArea input;
private JScrollBar scroll,scroll2;
private JButton encodeButton,decodeButton;
private JLabel image_input;
//elements for Menu
private JMenu file;
private JMenuItem encode;
private JMenuItem decode;
private JMenuItem exit;
/*
*Constructor for Steganography_View class
*@param name Used to set the title on the JFrame
*/
public Steganography_View(String name)
{
//set the title of the JFrame
super(name);
//Menubar
JMenuBar menu = new JMenuBar();
JMenu file = new JMenu(\"File\"); file.setMnemonic(\'F\');
encode = new JMenuItem(\"Encode\"); encode.setMnemonic(\'E\');
file.add(encode);
decode = new JMenuItem(\"Decode\"); decode.setMnemonic(\'D\');
file.add(decode);
file.addSeparator();
exit = new JMenuItem(\"Exit\"); exit.setMnemonic(\'x\'); file.add(exit);
menu.add(file);
setJMenuBar(menu);
// display rules
setResizable(true);//allow window to be resized: true?false
setBackground(Color.lightGray); /background color of window:
Color(int,int,int) setLocation(100,100); //location on the screen to display
window
setDefaultCloseOperation(EXIT_ON_CLOSE);//what to do on close operation: exit,
do_nothing, etc
setSize(WIDTH,HEIGHT); //set the size of the window
setVisible(true); //show the window: true?false
}
/*
*@return The menu item \'Encode\'
*/
public JMenuItem getEncode() { return encode;
}
/*
*@return The menu item \'Decode\'
*/
public JMenuItem getDecode() { return decode;
}
/*
*@return The menu item \'Exit\'
*/
public JMenuItem getExit() { return
exit; }
/*
*@return The TextArea containing the text to encode
*/
public JTextArea getText() { return
input; }
/*
*@return The JLabel containing the image to decode text from
*/
public JLabel getImageInput() { return image_input;
}
/*
*@return The JPanel displaying the Encode View
*/
public JPanel getTextPanel() { return new Text_Panel(); }
/*
*@return The JPanel displaying the Decode View
*/
public JPanel getImagePanel() { return new Image_Panel(); }
/*
*@return The Encode button
*/
public JButton getEButton() { return encodeButton; }
/*
*@return The Decode button
*/
public JButton getDButton() { return decodeButton; }
/*
*Class Text_Panel
*/
private class Text_Panel extends JPanel
{
/*
*Constructor to enter text to be encoded
*/
public Text_Panel()
{
//setup GridBagLayout
GridBagLayout layout = new GridBagLayout();
GridBagConstraints l.
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from
JPanel. Therefore, the panel you are asked to add to the center of the content pane is the \"game\"
object. 2. In part 4, at the end of the function, call validate(). This is not mentioned in the book,
but it is mentioned in the framework comments.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Game extends JPanel
{
private JButton [][] squares;
private TilePuzzle game;
public Game( int newSide )
{
game = new TilePuzzle( newSide );
setUpGameGUI( );
}
public void setUpGame( int newSide )
{
game.setUpGame( newSide );
setUpGameGUI( );
}
public void setUpGameGUI( )
{
removeAll( ); // remove all components
setLayout( new GridLayout( game.getSide( ),
game.getSide( ) ) );
squares = new JButton[game.getSide( )][game.getSide( )];
ButtonHandler bh = new ButtonHandler( );
// for each button: generate button label,
// instantiate button, add to container,
// and register listener
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j] = new JButton( game.getTiles( )[i][j] );
add( squares[i][j] );
squares[i][j].addActionListener( bh );
}
}
setSize( 300, 300 );
setVisible( true );
}
private void update( int row, int col )
{
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j].setText( game.getTiles( )[i][j] );
}
}
if ( game.won( ) )
{
JOptionPane.showMessageDialog( Game.this,
\"Congratulations! You won!\ Setting up new game\" );
// int sideOfPuzzle = 3 + (int) ( 4 * Math.random( ) );
// setUpGameGUI( );
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent ae )
{
for( int i = 0; i < game.getSide( ); i++ )
{
for( int j = 0; j < game.getSide( ); j++ )
{
if ( ae.getSource( ) == squares[i][j] )
{
if ( game.tryToPlay( i, j ) )
update( i, j );
return;
} // end if
} // end inner for loop
} // outer for loop
} // end actionPerformed method
} // end ButtonHandler class
} // end Game class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NestedLayoutPractice extends JFrame
{
private Container contents;
private Game game;
private BorderLayout bl;
private JLabel bottom;
// ***** Task 1: declare a JPanel named top
// also declare three JButton instance variables
// that will be added to the JPanel top
// these buttons will determine the grid size of the game:
// 3-by-3, 4-by-4, or 5-by-5
// Part 1 student code starts here:
// Part 1 student code ends here.
public NestedLayoutPractice()
{
super(\"Practicing layout managers\");
contents = getContentPane();
// ***** Task 2:
// instantiate the BorderLayout manager bl
// Part 2 student code starts here:
// set the layout manager of the content pane contents to bl:
game = new Game(3); // instantiating the GamePanel object
// add panel (game) to the center of the content pane
// Part 2 student code ends here.
bottom = new JLabel(.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdfoptokunal1
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, and creates a border around it
containing the title \"this is a JPanel.\"
2) Write a keyPressed method that behaves as follows. If the user presses the up arrow, the
method should output \"You pressed up\"using the System.out.printin method. Ifthe user presses
the down arrow, the method should output \"You pressed down\" using the System.out.printin
method.
3) Write a short class that represents a panelwith a single radio button that has the option
\"Yes\"and the option \"No.\" Bydefault, the Yes buttonshould be checked.
4) Suppose we have created a class called MyGUI, which represents a GUI. Write a programthat
creates a JFrame object, adds a MyGUI object to the frame and makes it visible.
5) Write a short class that represents a panelwith a single sliderthat has values from 0 to 250,
with largetick marks in incrementsof 50 and smalltick marks in increments of 10.
Solution
1)
/**
* The java Demo1 that cretes a titled border
* for jpanel.
* */
//Demo1.java
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class Demo1
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
//Create an instance of Jpanel
JPanel p1=new JPanel();
//Create an instance of TitledBorder
TitledBorder border = new TitledBorder(\"this is a JPanel\");
border.setTitleJustification(TitledBorder.CENTER);
//add border to panel ,p1
p1.setBorder(border);
//add panle to frame
frame.add(p1);
frame.setSize(250, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
2)
/**
* The java Demo2 that display a message
* for arrow up is pressed and arrow down
* key is pressed
*
* */
//Demo1.java
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class Demo2
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
//Create an instance of Jpanel
JPanel p1=new JPanel();
//Create an instance of TitledBorder
TitledBorder border = new TitledBorder(\"this is a JPanel\");
border.setTitleJustification(TitledBorder.CENTER);
//add border to panel ,p1
p1.setBorder(border);
p1.setFocusable(true);
//Add a KeyListener interface to the panel,p1
p1.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
/*Write to display pressed up
and pressed down */
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch( keyCode )
{
case KeyEvent.VK_UP:
System.out.println(\"You pressed up\");
break;
case KeyEvent.VK_DOWN:
System.out.println(\"You pressed down\");
break;
}
}
});
//add panle to frame
frame.add(p1);
frame.setSize(250, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
3)
/**
* the java program that deomons.
Gui programming a review - mixed contentYogesh Kumar
Class 12 IP Chapter 3 PPt, Mixed content ppt, GUI Programming - A review at a glance, (62 Slides, 5 MB), Homework_Ch3_PPT for school, Easy to understand, JAVA Basics PPt
import java.awt.Color;
import java.awt.Insets;
import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.BorderFactory;
/*
*Class Steganography_View
*/
public class Steganography_View extends JFrame
{
//size variables for window
private static int WIDTH = 500;
private static int HEIGHT = 400;
//elements for JPanel
private JTextArea input;
private JScrollBar scroll,scroll2;
private JButton encodeButton,decodeButton;
private JLabel image_input;
//elements for Menu
private JMenu file;
private JMenuItem encode;
private JMenuItem decode;
private JMenuItem exit;
/*
*Constructor for Steganography_View class
*@param name Used to set the title on the JFrame
*/
public Steganography_View(String name)
{
//set the title of the JFrame
super(name);
//Menubar
JMenuBar menu = new JMenuBar();
JMenu file = new JMenu(\"File\"); file.setMnemonic(\'F\');
encode = new JMenuItem(\"Encode\"); encode.setMnemonic(\'E\');
file.add(encode);
decode = new JMenuItem(\"Decode\"); decode.setMnemonic(\'D\');
file.add(decode);
file.addSeparator();
exit = new JMenuItem(\"Exit\"); exit.setMnemonic(\'x\'); file.add(exit);
menu.add(file);
setJMenuBar(menu);
// display rules
setResizable(true);//allow window to be resized: true?false
setBackground(Color.lightGray); /background color of window:
Color(int,int,int) setLocation(100,100); //location on the screen to display
window
setDefaultCloseOperation(EXIT_ON_CLOSE);//what to do on close operation: exit,
do_nothing, etc
setSize(WIDTH,HEIGHT); //set the size of the window
setVisible(true); //show the window: true?false
}
/*
*@return The menu item \'Encode\'
*/
public JMenuItem getEncode() { return encode;
}
/*
*@return The menu item \'Decode\'
*/
public JMenuItem getDecode() { return decode;
}
/*
*@return The menu item \'Exit\'
*/
public JMenuItem getExit() { return
exit; }
/*
*@return The TextArea containing the text to encode
*/
public JTextArea getText() { return
input; }
/*
*@return The JLabel containing the image to decode text from
*/
public JLabel getImageInput() { return image_input;
}
/*
*@return The JPanel displaying the Encode View
*/
public JPanel getTextPanel() { return new Text_Panel(); }
/*
*@return The JPanel displaying the Decode View
*/
public JPanel getImagePanel() { return new Image_Panel(); }
/*
*@return The Encode button
*/
public JButton getEButton() { return encodeButton; }
/*
*@return The Decode button
*/
public JButton getDButton() { return decodeButton; }
/*
*Class Text_Panel
*/
private class Text_Panel extends JPanel
{
/*
*Constructor to enter text to be encoded
*/
public Text_Panel()
{
//setup GridBagLayout
GridBagLayout layout = new GridBagLayout();
GridBagConstraints l.
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
Working with Layout Managers. Notes: 1. In part 2, note that the Game class inherits from
JPanel. Therefore, the panel you are asked to add to the center of the content pane is the \"game\"
object. 2. In part 4, at the end of the function, call validate(). This is not mentioned in the book,
but it is mentioned in the framework comments.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Game extends JPanel
{
private JButton [][] squares;
private TilePuzzle game;
public Game( int newSide )
{
game = new TilePuzzle( newSide );
setUpGameGUI( );
}
public void setUpGame( int newSide )
{
game.setUpGame( newSide );
setUpGameGUI( );
}
public void setUpGameGUI( )
{
removeAll( ); // remove all components
setLayout( new GridLayout( game.getSide( ),
game.getSide( ) ) );
squares = new JButton[game.getSide( )][game.getSide( )];
ButtonHandler bh = new ButtonHandler( );
// for each button: generate button label,
// instantiate button, add to container,
// and register listener
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j] = new JButton( game.getTiles( )[i][j] );
add( squares[i][j] );
squares[i][j].addActionListener( bh );
}
}
setSize( 300, 300 );
setVisible( true );
}
private void update( int row, int col )
{
for ( int i = 0; i < game.getSide( ); i++ )
{
for ( int j = 0; j < game.getSide( ); j++ )
{
squares[i][j].setText( game.getTiles( )[i][j] );
}
}
if ( game.won( ) )
{
JOptionPane.showMessageDialog( Game.this,
\"Congratulations! You won!\ Setting up new game\" );
// int sideOfPuzzle = 3 + (int) ( 4 * Math.random( ) );
// setUpGameGUI( );
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent ae )
{
for( int i = 0; i < game.getSide( ); i++ )
{
for( int j = 0; j < game.getSide( ); j++ )
{
if ( ae.getSource( ) == squares[i][j] )
{
if ( game.tryToPlay( i, j ) )
update( i, j );
return;
} // end if
} // end inner for loop
} // outer for loop
} // end actionPerformed method
} // end ButtonHandler class
} // end Game class
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NestedLayoutPractice extends JFrame
{
private Container contents;
private Game game;
private BorderLayout bl;
private JLabel bottom;
// ***** Task 1: declare a JPanel named top
// also declare three JButton instance variables
// that will be added to the JPanel top
// these buttons will determine the grid size of the game:
// 3-by-3, 4-by-4, or 5-by-5
// Part 1 student code starts here:
// Part 1 student code ends here.
public NestedLayoutPractice()
{
super(\"Practicing layout managers\");
contents = getContentPane();
// ***** Task 2:
// instantiate the BorderLayout manager bl
// Part 2 student code starts here:
// set the layout manager of the content pane contents to bl:
game = new Game(3); // instantiating the GamePanel object
// add panel (game) to the center of the content pane
// Part 2 student code ends here.
bottom = new JLabel(.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Strategies for Successful Data Migration Tools.pptxvarshanayak241
Data migration is a complex but essential task for organizations aiming to modernize their IT infrastructure and leverage new technologies. By understanding common challenges and implementing these strategies, businesses can achieve a successful migration with minimal disruption. Data Migration Tool like Ask On Data play a pivotal role in this journey, offering features that streamline the process, ensure data integrity, and maintain security. With the right approach and tools, organizations can turn the challenge of data migration into an opportunity for growth and innovation.
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
2. Chapter Goals
• To use layout managers toarrange user-interface components in a
container
• To use text components tocapture and display text in a graphical
application
• To become familiar with common user-interface components, such as
radio buttons, check boxes, and menus
• To browse the Java documentation effectively
3. Layout Management
• Build user interface by adding components into
containers.
• Use a layout manager to place the components.
• JFrame uses Flow layout bydefault.
4. Border Layout
Components are placed toward areas of a container NORTH, EAST, SOUTH,
WEST, or CENTER.
Specify one when adding components:
panel.setLayout(new BorderLayout());
panel.add(component, BorderLayout.NORTH);
Figure 1 Components Expand to Fill Space in the Border Layout
5. Grid Layout
Components are placed in boxes in a simple table arrangement.
Specify the size (rows then columns) of the grid.
Then add components which will be placed fromthe upper left,
across, thendown.
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 3));
buttonPanel.add(button7);
buttonPanel.add(button8);
buttonPanel.add(button9);
buttonPanel.add(button4);
. . .
Figure 2 The Grid Layout
6. Achieving Complex Layouts
Create complex layouts by nesting panels.
Give each panel an appropriate layout manager.
Panels have invisible borders, so you can use as many panels
as you need to organize components.
JPanel keypadPanel = new JPanel();
keypadPanel.setLayout(new BorderLayout());
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 3));
buttonPanel.add(button7);
buttonPanel.add(button8);
// . . .
keypadPanel.add(buttonPanel, BorderLayout.CENTER);
JLabel display = new JLabel("0");
keypadPanel.add(display, BorderLayout.NORTH);
Figure 3 Nesting Panels
7. Using Inheritance
Use inheritance forcomplex frames. Design a
subclass ofJFrame:
Store components as instance variables. Initialize
them in the constructor of your subclass.
Easy toadd helper methods toorganize code.
public class FilledFrame extends JFrame
{
// Use instance variables for components private JButton button;
private JLabel label;
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 100;
public FilledFrame()
{
// Now we can use a helper method createComponents();
// It is a good idea to set the size in the frame constructor
setSize(FRAME_WIDTH, FRAME_HEIGHT);
}
private void createComponents() {
button = new JButton("Click me!");
label = new JLabel("Hello, World!");
JPanel panel = new JPanel(); panel.add(button);
panel.add(label);
add(panel);
}
}
8. Using Inheritance
FillledFrameViewer2 main method:
public class FilledFrameViewer2
{
public static void main(String[] args)
{
JFrame frame = new FilledFrame();
frame.setTitle("A frame with two components");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
9. Common Error 20.1
You add components like buttons or labels:
panel.add(button);
panel.add(label);
panel.add(carComponent);
Default size for component is 0 by 0 pixels so car component
will not be visible.
Use setPreferredSize:
carComponent.setPreferredSize(new Dimension(CAR_COMPONENT_WIDTH, CAR_COMPONENT_HEIGHT));
Only needed for painted components.
10. Processing Text Input
Dialog boxes allows for user input.
Popping up a separate dialog boxfor each input is not a natural
user interface.
Most graphical programs collect text input throughtext fields.
The JTextField class provides a textfield.
Specify the width for the text field.
If the user exceeds this width, text will ‘scroll’ left.
final int FIELD_WIDTH = 10;
final JTextField rateField = new JTextField(FIELD_WIDTH);
Figure 4 An Application with a Text Field
11. Add a Label and a Button
Add a label to describe the field:
JLabel rateLabel = new JLabel("Interest Rate: ");
Add a button for user to indicate input is complete.
actionPerformed method can use getText to get input as a
String.
Convert to a numeric value if used for
calculations.
class AddInterestListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
double rate = Double.parseDouble(rateField.getText());
double interest = balance * rate / 100;
balance = balance + interest;
resultLabel.setText("Balance: " + balance);
}
}
12. section_2_1/InvestmentFrame2.java
/**
A frame that shows the growth of an investment with variable interest.
*/
public class InvestmentFrame2 extends JFrame
{
private static final int FRAME_WIDTH = 450;
private static final int FRAME_HEIGHT = 100;
private static final double DEFAULT_RATE = 5;
private static final double INITIAL_BALANCE = 1000;
private JLabel rateLabel;
private JTextField rateField;
private JButton button;
private JLabel resultLabel;
private double balance;
public InvestmentFrame2()
{
balance = INITIAL_BALANCE;
resultLabel = new JLabel("Balance: " + balance);
1 import java.awt.event.ActionEvent;
2 import java.awt.event.ActionListener;
3 import javax.swing.JButton;
4 import javax.swing.JFrame;
5 import javax.swing.JLabel;
6 import javax.swing.JPanel;
7 import javax.swing.JTextField;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
createTextField();
createButton();
13. Text Areas
Create multi-linetext areas with a JTextArea object.
Set the size in rows and columns.
final int ROWS = 10; // Lines of text
final int COLUMNS = 30; // Characters in each row
JTextArea textArea = new JTextArea(ROWS, COLUMNS);
Use the setText method to set the text of a text field or text
area.
textArea.append(balance + "n");
Can use the text area for display purposes only.
textArea.setEditable(false);
14. TextComponent Class
JTextField and JTextArea are subclasses of
JTextComponent.
setText and setEditable are declared in the
JTextComponent class.
Inherited by JTextField and JTextArea.
append method is only declared in JTextArea.
Figure 5 A Part ofthe Hierarchy ofSwing User-Interface Components
15. Scrolling
To add scroll bars, use JScrollPane:
JScrollPane scrollPane = new JScrollPane(textArea);
Figure 6 The Investment Application with a Text Area Inside Scroll Bars
16. section_2_2/InvestmentFrame3.java
/**
A frame that shows the growth of an investment with variable interest,
using a text area.
*/
public class InvestmentFrame3 extends JFrame
{
private static final int FRAME_WIDTH = 400;
private static final int FRAME_HEIGHT = 250;
private static final int AREA_ROWS = 10;
private static final int AREA_COLUMNS = 30;
private static final double DEFAULT_RATE = 5;
private static final double INITIAL_BALANCE = 1000;
private JLabel rateLabel;
private JTextField rateField;
private JButton button;
private JTextArea resultArea;
private double balance;
1 import java.awt.event.ActionEvent;
2 import java.awt.event.ActionListener;
3 import javax.swing.JButton;
4 import javax.swing.JFrame;
5 import javax.swing.JLabel;
6 import javax.swing.JPanel;
7 import javax.swing.JScrollPane;
8 import javax.swing.JTextArea;
9 import javax.swing.JTextField;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public InvestmentFrame3()
17. Choices
GUI components for selections:
Radio Buttons For a small set of mutually exclusive choices.
Check Boxes For a binary choice.
Combo Boxes For a large set of choices.
18. Radio Buttons
Only one button in a set can be selected.
Selecting a button clears previous selection.
In an old fashioned radio, pushing down one station button released theothers.
Create each buttonindividually.
Add all buttons in the set to a ButtonGroup object:
JRadioButton smallButton = new JRadioButton("Small");
JRadioButton mediumButton = new JRadioButton("Medium");
JRadioButton largeButton = new JRadioButton("Large");
ButtonGroup group = new ButtonGroup();
group.add(smallButton);
group.add(mediumButton);
group.add(largeButton);
Use isSelected to find out whether a button is selected, like:
if (largeButton.isSelected()) { size = LARGE_SIZE; }
19. Radio Button Panels
Use a panel for each set of radio buttons.
The default border for a panel is invisible (no border).
You can add a border to a panel to make it visible.
Also add a title.
JPanel panel = new JPanel();
panel.add(smallButton);
panel.add(mediumButton);
panel.add(largeButton);
panel.setBorder(new TitledBorder(new EtchedBorder(),"Size"));
21. Check Boxes
A check boxhas two states: checked and unchecked.
Use for choices that are not mutually exclusive.
For example in Figure 7, text may be Italic,
Bold, both or neither.
Because check boxsettings do not exclude each other, you do
not need to place a set of check boxes inside a button group.
Radio buttons are round and have a black dot when selected.
Check boxes are square and have a check mark when selected.
Construct a textbox:
JCheckBox italicCheckBox = new JCheckBox("Italic");
Use isSelected to find out whether a check boxis selected.
22. Combo Boxes
A combo boxis a combination of a list and a text field.
Clicking the arrow to the right of the text field opens the list of
selections.
Use a combo boxfor a large set of choices.
Use when radio buttons would take up too much space.
It can be either:
Closed (shows one selection).
Open, showing multiple selections.
It can also be editable:
Type a selection into a blank line.
facenameCombo.setEditable();
23. Adding and Selecting Items
Add text ‘items’ to a combo boxthat will show in the list:
JComboBox facenameCombo = new JComboBox();
facenameCombo.addItem("Serif");
facenameCombo.addItem("SansSerif");
. . .
Use the getSelectedItem method to return the selected item
(as an Object).
Combo boxes can store other objects in addition to strings, so
casting to a string may be required:
String selectedString = (String) facenameCombo.getSelectedItem();
Figure 8 An Open Combo Box
24. Handling Input Events
Radio buttons, check boxes, and combo boxes generate an
ActionEvent when selected.
In FontViewer program, listener gets all events.
Simply check the state of each component using isSelected
and getSelectedItem methods.
Then redraw the label with the new font.
26. section_3/FontViewer.java
1 import javax.swing.JFrame;
2
3 /**
4 This program allows the user to view font effects.
5 */
6 public class FontViewer
7 {
8 public static void main(String[] args)
9 {
10 JFrame frame = new FontFrame();
11 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 frame.setTitle("FontViewer");
13 frame.setVisible(true);
14 }
15 }
27. section_3/FontFrame.java
/**
This frame contains a text sample and a control panel
to change the font of the text.
*/
public class FontFrame extends JFrame
{
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 400;
private JLabel label;
private JCheckBox italicCheckBox;
private JCheckBox boldCheckBox;
private JRadioButton smallButton;
private JRadioButton mediumButton;
private JRadioButton largeButton;
private JComboBox facenameCombo;
private ActionListener listener;
1 import java.awt.BorderLayout;
2 import java.awt.Font;
3 import java.awt.GridLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import javax.swing.ButtonGroup;
7 import javax.swing.JButton;
8 import javax.swing.JCheckBox;
9 import javax.swing.JComboBox;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JRadioButton;
14 import javax.swing.border.EtchedBorder;
15 import javax.swing.border.TitledBorder;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
Constructs the frame.
28. Designing a User Interface
Make a sketch of the component layout. Draw all the buttons,
labels, text fields, and borders on a sheet of graph paper.
Find groupings of adjacent components with the same layout.
Look for adjacent components top to bottomor left to right.
Identify layouts for each group:
For horizontal components, use flow layout.
For vertical components, use a grid layout with one column.
Group the groups together:
Look at each group as one blob.
Group the blobs together into larger groups.
29. Designing a User Interface
Write the code to generate the layout.
JPanel radioButtonPanel = new JPanel();
radioButtonPanel.setLayout(new GridLayout(3, 1));
radioButton.setBorder(new TitledBorder(new EtchedBorder(), "Size"));
radioButtonPanel.add(smallButton);
radioButtonPanel.add(mediumButton);
radioButtonPanel.add(largeButton);
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setLayout(new GridLayout(2, 1));
checkBoxPanel.add(pepperoniButton());
checkBoxPanel.add(anchoviesButton());
JPanel pricePanel = new JPanel();
// Uses FlowLayout by default
pricePanel.add(new JLabel("Your Price:"));
pricePanel.add(priceTextField);
JPanel centerPanel = new JPanel(); // Uses FlowLayout
centerPanel.add(radioButtonPanel);
centerPanel.add(checkBoxPanel);
// Frame uses BorderLayout by default
add(centerPanel, BorderLayout.CENTER);
add(pricePanel, BorderLayout.SOUTH);
30. Use a GUI Builder
A GUI builder reduces the tedious work:
Drag and drop components onto a panel.
Customize fonts, colors, text, and so on with a dialog box.
Define event handlers by picking the event to process and provide the
code snippet for the listener method.
Powerful layout manager GroupLayout designed to be used
by GUI builders.
31. Use a GUI Builder
Try the free NetBeans development environment, available from
http://netbeans.org.
Figure 10 A GUI Builder
32. M enus
A frame can contain a menu bar.
Menu bar contains menus.
Menu contains submenus and menu items.
Menu items can be added to each menu or submenu.
First, add the menu bar to the frame:
public class MyFrame extends JFrame
{
public MyFrame()
{
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
. . .
}
. . .
}
34. M enus
Add menus to the menu bar:
JMenu fileMenu = new JMenu("File");
JMenu fontMenu = new JMenu("Font");
menuBar.add(fileMenu);
menuBar.add(fontMenu);
Add menu items and subitems:
JMenuItem exitItem = new JMenuItem("Exit");
fileMenu.add(exitItem);
JMenu styleMenu = new JMenu("Style");
fontMenu.add(styleMenu); // A submenu
Add a listener to each menu item (not to menus or menu bar):
ActionListener listener = new ExitItemListener();
exitItem.addActionListener(listener);
35. M enus
Use a separate method for each menu or set of related menus:
public JMenu createFaceMenu()
{
JMenu menu = new JMenu("Face");
menu.add(createFaceItem("Serif"));
menu.add(createFaceItem("SansSerif"));
menu.add(createFaceItem("Monospaced"));
return menu;
}
36. M enus
createFaceItem method needs to set the fontface:
Set the current face name.
Make the new font from the current face, size, and style, and apply it to
label.
Create a FaceItemListener class to listen for face item
name actions:
class FaceItemListener implements ActionListener
{
private String name;
public FaceItemListener(String newName) { name = newName; }
public void actionPerformed(ActionEvent event)
{
faceName = name; // Sets an instance variable of the frame class
setLabelFont();
}
}
Install a listener object with the appropriate name:
public JMenuItem createFaceItem(String name)
{
JMenuItem item = new JMenuItem(name);
ActionListener listener = new FaceItemListener(name);
item.addActionListener(listener);
return item;
}
37. M enus
Better to make a local inner class in the createFaceItem
method.
actionPerformed method can access the name parameter
variable directly (rather than passing it).
public JMenuItem createFaceItem(final String name)
// Final variables can be accessed from an inner class method
{
class FaceItemListener implements ActionListener
// A local inner class
{
public void actionPerformed(ActionEvent event)
{
facename = name; // Accesses the local variable name setLabelFont();
}
}
JMenuItem item = new JMenuItem(name);
ActionListener listener = new FaceItemListener(name);
item.addActionListener(listener);
return item;
}
Same strategy used for the createSizeItem and
createStyleItem methods.
38. section_4/FontViewer2.java
1 import javax.swing.JFrame;
2
3 /**
4 This program uses a menu to display font effects.
5 */
6 public class FontViewer2
7 {
8 public static void main(String[] args)
9 {
10 JFrame frame = new FontFrame2();
11 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 frame.setTitle("FontViewer");
13 frame.setVisible(true);
14 }
15 }
39. section_4/FontFrame2.java
/**
This frame has a menu with commands to change the font
of a text sample.
*/
public class FontFrame2 extends JFrame
{
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 400;
private JLabel label;
private String facename;
private int fontstyle;
private int fontsize;
/**
Constructs the frame.
*/
public FontFrame2()
{
// Construct text sample
label = new JLabel("Big Java");
add(label, BorderLayout.CENTER);
1 import java.awt.BorderLayout;
2 import java.awt.Font;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import javax.swing.JFrame;
6 import javax.swing.JLabel;
7 import javax.swing.JMenu;
8 import javax.swing.JMenuBar;
9 import javax.swing.JMenuItem;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Construct menu
JMenuBar menuBar = new JMenuBar();
40. Exploring the Swing Documentation
Consider an example application: Use sliders to set colors of
red, green and blue.
Swing user-interface toolkit provides a large set of components.
How do you know if there is a slider?
Buy a book that illustrates all Swing components.
Run the sample Swing application included in the Java Development Kit.
Look at the names of all of the classes that start with J and decide that
JSlider may be a good candidate.
Figure 12 A Color Viewer withSliders
41. JSlider Documentation and Use
Now ask some questions about JSlider:
How do I construct a JSlider?
How can I get notified when the user has moved it? How can I
tell to which value the user has set it?
Unfortunately, documentation for JSlider is voluminous:
Over 50 methods in the JSlider class. Over 250
inherited methods.
Some of the method descriptions look downright scary.
Concentrate on what you will need:
Constructors. Event
handling. Get the value.
43. JSlider Constructor Choice
We want a slider value between 0 and 255.
Find a constructor that will do what we need:
public JSlider()
Creates a horizontal slider with the range 0 to 100 and an initial
value of50.
public JSlider(BoundedRangeModel brm)
Creates a horizontal slider using the specified
BoundedRangeModel.
public JSlider(int min, int max, int value)
Creates a horizontal slider using the specified min, max, and
value.
44. JSlider Event Handling
Goal: Add a change event listener to each slider.
There is no addActionListener method.
Possible option:
public void addChangeListener(ChangeListener l)
Looks like AddActionListener calls
stateChanged(ChangeEvent e) whenever the user adjusts
the slider.
45. Figure 14 A Mysterious Method Description from the API Documentation
46. JSlider Event Handling
So the planis:
Setup three sliders and one ChangeListener object.
Use AddChangeListener, passing our ChangeListener to each
slider.
In the stateChanged method, check the values of the colors and repaint
the panel.
Figure 15 The Components of the Color Viewer Frame
47. section_5/ColorViewer.java
1 import javax.swing.JFrame;
2
3 public class ColorViewer
4 {
5 public static void main(String[] args)
6 {
7 JFrame frame = new ColorFrame();
8 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9 frame.setVisible(true);
10 }
11 }