myswing パッケージ

  ウインドウ + DB アクセス



コマンドラインベースと、Eclipse 用のワークスペースと両方カタログしています。
DB は、MDB を使用しているので、build.bat で DSN が定義されます。

※ eclipse で開いた時、最初に CLWin.java を表示させてディレクトリ内のソースをビルドして下さい







readme.txt
1) build.bat をダブルクリックして実行します。
2) 商品分類マスタメンテ ディレクトリに移動して、ビルド.wsf を実行します
3) 実行.wsf を実行します

myswing.mkp は MKEditor 用のプロジェクトです。
Terapadのツール登録.txt は、TeraPad のツールの登録パラメータです


workspace ディレクトリは、Eclipse 用です。

■著作権その他

このプログラムはフリーです。どうぞ自由に御使用ください。
著作権は作者である私が保有しています。
また、本ソフトを運用した結果については、作者は一切責任を
負えせんのでご了承ください。

lightbox

  
package myswing;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CLWin extends JFrame {
	
	Container MainArea = null;
	public JPanel Client = new JPanel();	// クライアント領域
	JPanel StatusArea = new JPanel();	// ステータスバー領域
	public JLabel Status = new JLabel("ステータスバー");
	public JMenuBar MenuBar = new JMenuBar();
	public int RowPitch = 25;
	public int BaseLine = 1;
	public int BasePosition = 0;

	// コンストラクタ
	public CLWin() {
		
		this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		
		this.setSize(800,600);
		
		MainArea = this.getContentPane();
		MainArea.add(Client,BorderLayout.CENTER);
		MainArea.add(StatusArea,BorderLayout.SOUTH);
		
		Client.setLayout( null );
		
		StatusArea.setBorder( BorderFactory.createLineBorder( Color.GRAY ));
		StatusArea.setLayout( new FlowLayout( FlowLayout.LEFT ));
		StatusArea.add( Status );

		Status.setFont(new Font("MS Pゴシック", 0, 12));
		
	}

	// ウインドウの中央移動
	public void CenterWindow() {
		
		Toolkit Tool;
		Dimension DesktopSize;
		Dimension WindowSize;
		
		Tool = this.getToolkit();
		DesktopSize = Tool.getScreenSize();
		WindowSize = this.getSize();
		this.move(
			(DesktopSize.width-WindowSize.width)/2,
			(DesktopSize.height-WindowSize.height)/2
		);
		
	}
	
	// ボタン実装 (1)
	public void AddButton(ActionListener MyEvent, LboxButton LButton) {
		
		Client.add( LButton );
		LButton.addActionListener(MyEvent);
		
	}

	// ボタン実装 (2)
	public void AddButton(ActionListener MyEvent, LboxButton LButton, int x, int y ) {
		
		LButton.setLocation(BasePosition+x,(BaseLine+y)*RowPitch+5);
		Client.add( LButton );
		LButton.addActionListener(MyEvent);
		
	}

	// ラベル実装
	public void AddLabel(LboxLabel LLabel, int x, int y ) {
		
		LLabel.setLocation(BasePosition+x,(BaseLine+y)*RowPitch+5);
		Client.add( LLabel );
		
	}

	// エディトコントロール実装
	public void AddEdit(LboxEdit LEdit, int x, int y ) {
		
		LEdit.setLocation(BasePosition+x,(BaseLine+y)*RowPitch+5);
		Client.add( LEdit );
		
	}
	
	// コンボボックス実装
	public void AddCombo(ActionListener MyEvent, LboxCombobox LCombo, int x, int y ) {
		
		LCombo.setLocation(BasePosition+x,(BaseLine+y)*RowPitch+5);
		Client.add( LCombo );
		LCombo.addActionListener(MyEvent);
		
	}
	
	// メニュー実装
	public void CreateMenu() {

		setJMenuBar( MenuBar );
		
	}
	
	// ポップアップメニュー実装
	public void AddMenu(LboxMenu Popup) {

		MenuBar.add( Popup );
		
	}
	
	// メニュー項目実装
	public void AddMenu(ActionListener MyEvent, LboxMenu Popup, LboxMenuItem Item) {

		Popup.add( Item );
		Item.addActionListener(MyEvent);
		
	}
	
	// 単純確認メッセージボックス
	public void MsgOk(String Message) {
		
		JOptionPane.showMessageDialog(this,Message);
		
	}
}
  




  LboxButton.java



  
package myswing;

import java.awt.*;
import javax.swing.*;

public class LboxButton extends JButton {
	
	// コンストラクタ
	public LboxButton() {
		
		Initialize();
		
	}
	
	public LboxButton(String Text) {
		
		this.setText(Text);
		Initialize();

	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		this.setSize(100,20);
		
	}

	public void SetWidth(int Width) {
		
		int Height;
		
		Height = this.getHeight();
		this.setSize(Width,Height);

	}
}
  



  LboxEdit.java

  
package myswing;

import java.awt.*;
import javax.swing.*;

public class LboxEdit extends JTextField {
	
	// コンストラクタ
	public LboxEdit() {
		
		Initialize();
		
	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		this.setSize(100,20);
		this.setText("");
		
	}

	public void SetWidth(int Width) {
		
		int Height;
		
		Height = this.getHeight();
		this.setSize(Width,Height);

	}

}
  



  LboxLabel.java

  
package myswing;

import java.awt.*;
import javax.swing.*;

public class LboxLabel extends JLabel {
	
	// コンストラクタ
	public LboxLabel() {
		
		Initialize();
		
	}
	
	public LboxLabel(String Text) {
		
		this.setText(Text);
		Initialize();

	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		this.setSize(100,20);
		
	}

	public void SetWidth(int Width) {
		
		int Height;
		
		Height = this.getHeight();
		this.setSize(Width,Height);

	}

}
  



  LboxDatabase.java

  
package myswing;

import java.sql.*;

public class LboxDatabase {

	private Connection con;
	public Statement stmt;
	public ResultSet rset;
	public String DriverName = "sun.jdbc.odbc.JdbcOdbcDriver";
	public String ConnectionUrl = "";
	public String ConnectionDbname = "";
	public String ConnectionUser = "";
	public String ConnectionPass = "";
	public String ErrorMessage = "";
	
	// *****************************************************
	// コンストラクタ
	// *****************************************************
	public LboxDatabase() {
		
		Initialize();
	
	}

	// *****************************************************
	// 初期化
	// *****************************************************
	public void Initialize( ) {

	}

	// *****************************************************
	// ドライバ文字列セット
	// *****************************************************
	public void setDriverName( String strName ) {

		DriverName = strName;

	}

	// *****************************************************
	// DB 接続 URL セット
	// *****************************************************
	public void setConnectionUrl( String strUrl ) {

		ConnectionUrl = strUrl;

	}

	// *****************************************************
	// DB 接続 Dbname セット
	// *****************************************************
	public void setConnectionDbname( String strUrl ) {

		ConnectionDbname = strUrl;

	}

	// *****************************************************
	// DB 接続 User セット
	// *****************************************************
	public void setConnectionUser( String strUser) {

		ConnectionUser = strUser;

	}

	// *****************************************************
	// DB 接続 Password セット
	// *****************************************************
	public void setConnectionPass( String strPass ) {

		ConnectionPass = strPass;

	}

	// *****************************************************
	// DB 接続
	// *****************************************************
	public boolean Connect( ) {


		ErrorMessage = "";
		
		try {
			Class.forName( DriverName );
			
			con = DriverManager.getConnection(
				ConnectionUrl,
				ConnectionUser,
				ConnectionPass
			);
			stmt = con.createStatement();
			if ( !ConnectionDbname.equals( "" ) ) {
				stmt.executeUpdate(
					"use " + ConnectionDbname
				);
			}

			return true;
		}
		catch( ClassNotFoundException e ) {
			ErrorMessage = e.getMessage();
			return false;
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			return false;
		}

	}

	// *****************************************************
	// DB 接続解除
	// *****************************************************
	public void DisConnect( ) {

		ErrorMessage = "";
		
		try {
			stmt.close();
			con.close();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

	}

	// *****************************************************
	// レコードセット取得
	// *****************************************************
	public boolean Query( String Sql ) {

		ErrorMessage = "";
		boolean bRet = true;

		try {
			rset = stmt.executeQuery ( Sql );
			bRet = rset.next();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			bRet = false;
		}

		return bRet;
	}
	public boolean Query()  {

		ErrorMessage = "";
		boolean bRet = true;

		try {
			bRet = rset.next();
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			bRet = false;
		}

		return bRet;
	}

	// *****************************************************
	// 列データ取得
	// *****************************************************
	public String Fields( String strName ) {

		ErrorMessage = "";
		String strResult = "";

		try {
			strResult = rset.getString( strName );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

		return strResult;
	}
	public String Fields( int nIndex ) {

		ErrorMessage = "";
		String strResult = "";

		try {
			strResult = rset.getString( nIndex );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
		}

		return strResult;
	}

	// *****************************************************
	// DB 更新処理
	// *****************************************************
	public int Execute( String Query ) {

		ErrorMessage = "";

		int nRet;

		try {
			nRet = stmt.executeUpdate( Query );
		}
		catch( SQLException e ) {
			ErrorMessage = e.getMessage();
			return -1;
		}

		return nRet;

	}

	// *****************************************************
	// データ一覧をコンボボックスにセット
	// *****************************************************
	public boolean LoadSqlData( LboxCombobox LCombo, String Query ) {

		boolean bRet;
		boolean bOk = false;
		String strData,strText;

		LCombo.byFuncton = true;
		
		LCombo.Reset();
		
		bRet = this.Query(Query);
		while( bRet ) {
			bOk = true;
			strData = this.Fields(1);
			strText = this.Fields(2);
			LCombo.Add(strData,strText);
			bRet = this.Query();
		}

		return bRet;

	}
}
  



  LboxCombobox.java

  
package myswing;

import java.awt.*;
import javax.swing.*;

import java.util.*;

public class LboxCombobox extends JComboBox {
	
	private Hashtable listData = null;
	public boolean byFuncton = false;
	
	// コンストラクタ
	public LboxCombobox() {
		
		Initialize();
		
	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		this.setSize(100,20);
		this.setBackground(new Color(255,255,255));
		listData = new Hashtable();
		byFuncton = false;
		
	}

	public void SetWidth(int Width) {
		
		int Height;
		
		Height = this.getHeight();
		this.setSize(Width,Height);

	}

	public void Add(String Code, String Data) {
		
		if ( Code == null ) {
			Code = "";
		}
		if ( Data == null ) {
			Data = "";
		}
		
		this.addItem(Data);
		listData.put(Data,Code);
	}
	
	public void Delete(int nIndex) {
		
		String Data = "";
		
		Data = this.getItemAt(nIndex).toString();
		
		this.removeItemAt(nIndex);
		listData.remove(Data);
		
	}
	
	public void Reset() {
		
		this.removeAllItems();
		listData.clear();
		
	}
	
	public int Count() {
		
		return this.getItemCount();
		
	}
	
	public String GetText(int nIndex) {
		
		return this.getItemAt(nIndex).toString();
		
	}
	
	public String GetData(int nIndex) {
		
		String Data = "";
		Data = this.getItemAt(nIndex).toString();
		return listData.get(Data).toString();
		
	}
	
	public void Select(int nIndex) {
		
		this.byFuncton = true;		
		
		try {
			this.setSelectedIndex(nIndex);
		}
		catch ( IllegalArgumentException e ) {
			this.setSelectedIndex(0);
		}
		
	}
	
	public boolean ByGuiChanged () {
		
		if ( this.byFuncton ) {
			this.byFuncton = false;
			return false;
		}
		return true;
	}
}
  



  LboxMenu.java

  
package myswing;

import java.awt.*;
import javax.swing.*;

public class LboxMenu extends JMenu {
	
	// コンストラクタ
	public LboxMenu() {
		
		Initialize();
		
	}
	
	public LboxMenu(String Text) {
		
		this.setText(Text);
		Initialize();

	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		
	}

}
  



  LboxMenuItem.java

  
package myswing;

import java.awt.*;
import javax.swing.*;

public class LboxMenuItem extends JMenuItem {
	
	// コンストラクタ
	public LboxMenuItem() {
		
		Initialize();
		
	}
	
	public LboxMenuItem(String Text) {
		
		this.setText(Text);
		Initialize();

	}
	
	private void Initialize() {
	
		this.setFont(new Font("MS Pゴシック", 0, 12));
		
	}

}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ