Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to list attributes in a JAR manifest file. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
List attributes in a JAR manifest file. 16-Aug-04
Category
Files Operation
Language
JBuilder All Versions
Views
265
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Darley, F. Joe
Reference URL:
			
1 package samplecode; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import java.util.jar.*; 7 import java.io.*; 8 import java.util.*; 9 10 /** 11 * <p>Title: Font Names </p> 12 * <p>Description: This program shows how to read the attirbutes 13 * <p> from a JAR manifest file</p> 14 * <p>Company: Developer's super Page.com</p> 15 */ 16 17 18 public class SampleFrame extends JFrame { 19 JPanel contentPane; 20 BorderLayout borderLayout1 = new BorderLayout(); 21 JPanel jpnlMain = new JPanel(); 22 DefaultListModel model = new DefaultListModel(); 23 JLabel jLabel1 = new JLabel(); 24 JButton jButton2 = new JButton(); 25 JTextArea jTextArea1 = new JTextArea(); 26 JTextField jTextField1 = new JTextField(); 27 JLabel jLabel2 = new JLabel(); 28 JTextField jTextField2 = new JTextField(); 29 30 //Construct the frame 31 public SampleFrame() { 32 enableEvents(AWTEvent.WINDOW_EVENT_MASK); 33 try { 34 jbInit(); 35 } 36 catch(Exception e) { 37 e.printStackTrace(); 38 } 39 } 40 41 //Component initialization 42 private void jbInit() throws Exception { 43 contentPane = (JPanel) this.getContentPane(); 44 contentPane.setLayout(borderLayout1); 45 this.setSize(new Dimension(475, 300)); 46 this.setTitle("Jar Attribute Reader"); 47 this.addHierarchyBoundsListener(new 48 SampleFrame_this_hierarchyBoundsAdapter(this)); 49 jpnlMain.setLayout(null); 50 contentPane.setMinimumSize(new Dimension(300, 300)); 51 contentPane.setPreferredSize(new Dimension(300, 256)); 52 jpnlMain.setDebugGraphicsOptions(0); 53 jpnlMain.setMinimumSize(new Dimension(400, 256)); 54 jpnlMain.setPreferredSize(new Dimension(400, 256)); 55 jpnlMain.addKeyListener(new SampleFrame_jpnlMain_keyAdapter(this)); 56 jButton2.setBounds(new Rectangle(162, 232, 148, 34)); 57 jButton2.setText("GetInfo"); 58 jButton2.addActionListener(new SampleFrame_jButton2_actionAdapter(this)); 59 jTextArea1.setText("jTextArea1"); 60 jTextArea1.setBounds(new Rectangle(21, 8, 431, 176)); 61 jLabel2.setText("File Name:"); 62 jLabel2.setBounds(new Rectangle(33, 201, 55, 19)); 63 jTextField2.setFont(new java.awt.Font("Dialog", 1, 11)); 64 jTextField2.setText("jTextField2"); 65 jTextField2.setBounds(new Rectangle(169, 195, 129, 28)); 66 contentPane.add(jpnlMain, BorderLayout.CENTER); 67 jpnlMain.add(jTextArea1, null); 68 jpnlMain.add(jLabel2, null); 69 jpnlMain.add(jTextField2, null); 70 jpnlMain.add(jButton2, null); 71 72 } 73 74 //Overridden so we can exit when window is closed 75 protected void processWindowEvent(WindowEvent e) { 76 super.processWindowEvent(e); 77 if (e.getID() == WindowEvent.WINDOW_CLOSING) { 78 System.exit(0); 79 } 80 } 81 82 83 void jButton1_actionPerformed(ActionEvent e) { 84 85 86 } 87 88 void jButton2_actionPerformed(ActionEvent e) { 89 try { 90 // used to append data in the for loop 91 String sData =""; 92 93 // Open the JAR file give by the textfield 94 JarFile jarfile = new JarFile(jTextField2.getText()); 95 96 97 // Get the manifest 98 Manifest manifest = jarfile.getManifest(); 99 100 // Get the main attributes in the manifest 101 Attributes attrs = (Attributes)manifest.getMainAttributes(); 102 103 // Enumerate each attribute 104 for (Iterator it=attrs.keySet().iterator(); it.hasNext(); ) { 105 // Get attribute name 106 Attributes.Name aName = (Attributes.Name)it.next(); 107 108 // Get attribute value 109 String aValue = attrs.getValue(aName); 110 sData+="Name=" + aName + " Value="+aValue+"\n"; 111 112 } 113 jTextArea1.setText(sData); 114 } catch (IOException e1) { 115 } 116 117 } 118 119 } 120 class SampleFrame_this_hierarchyBoundsAdapter extends 121 java.awt.event.HierarchyBoundsAdapter { 122 SampleFrame adaptee; 123 124 SampleFrame_this_hierarchyBoundsAdapter(SampleFrame adaptee) { 125 this.adaptee = adaptee; 126 } 127 128 } 129 130 131 132 class SampleFrame_jpnlMain_keyAdapter extends java.awt.event.KeyAdapter { 133 SampleFrame adaptee; 134 135 SampleFrame_jpnlMain_keyAdapter(SampleFrame adaptee) { 136 this.adaptee = adaptee; 137 } 138 139 } 140 141 class SampleFrame_jButton2_actionAdapter implements java.awt.event.ActionListener { 142 SampleFrame adaptee; 143 144 SampleFrame_jButton2_actionAdapter(SampleFrame adaptee) { 145 this.adaptee = adaptee; 146 } 147 public void actionPerformed(ActionEvent e) { 148 adaptee.jButton2_actionPerformed(e); 149 } 150 }
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC