adjacency.java~95~
来自「拓扑排序实现排课功能 8学期任意多门课程排序」· JAVA~95~ 代码 · 共 779 行 · 第 1/2 页
JAVA~95~
779 行
package course;
/**
* <p>Title:邻接矩阵 </p>
*
* <p>Description: 建立邻接矩阵及其基本方法</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company:www.bchine.com </p>
*
* @author lipiji
* @version 1.0
*/
public class Adjacency {
int noEdge = 0;//没有边
public static int n;//点的个数
int e = 0;//边的条数
public static int pos[];//过度数组
void InitializePos(int i) {
pos = new int[i + 1];//初始化
}
void DeactivatePos(int n) {
for (int i = 0; i <= n; i++) {
pos[i] = 0;
}
}
public void makeAdjacency(int Vertices, int noEdge, int a[][]) {
this.n = Vertices;//顶点数
e = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = noEdge;//初始化邻接矩阵
}
}
}
//检查是否已经存在
public Boolean Exist(int i, int j, int a[][]) {
if (i < 1 || j < 1 || i > n || j > n
|| a[i][j] == noEdge) {
return false;
}
return true;
}
public void Add(int i, int j, int w, int a[][]) {//添加边,代表前者是后者的先行课
if (i < 1 || j < 1 || i > n ||
j > n || i == j || a[i][j] != noEdge) {
System.out.println("Add throw BadInput();");//不合法输入
}
a[i][j] = w;//赋权值
e++;//边数
}
public void Delete(int i, int j, int a[][]) {//删除
if (i < 1 || j < 1 || i > n ||
j > n || a[i][j] == noEdge) {
System.out.println("Delete throw BadInput();");
}
a[i][j] = noEdge;
e--;
}
public int OutDegree(int i, int a[][]) {//出度
if (i < 1 || i > n) {
System.out.println("OutDegree throw BadInput();");
}
int sum = 0;
for (int j = 1; j <= n; j++) {
if (a[i][j] != noEdge) {//和i邻接的顶点
sum++;
}
}
return sum;
}
public int InDegree(int i, int a[][]) {//入度
if (i < 1 || i > n) {
System.out.println("InDegree throw BadInput();");
}
int sum = 0;
for (int j = 1; j <= n; j++) {
if (a[j][i] != noEdge) {
sum++;
}
}
return sum;
}
int Begin(int i, int a[][]) {
//获取和当前点邻接的顶点
if (i < 1 || i > n) {
System.out.println("Begin throw BadInput();" + i);
}
int j = 0;
for (j = 1; j <= n; j++) {
if (a[i][j] != noEdge) {
pos[i] = j;//中间变量
return j;//返回点
}
}
pos[i] = n + 1;
return 0;//若没有电则返回 0
}
public int NextVertex(int i, int a[][]) {//下一个顶点
if (i < 1 || i > n) {
System.out.println("NextVertex throw BadInput();" + i);
}
for (int j = pos[i] + 1; j <= n; j++) {
if (a[i][j] != noEdge) {
pos[i] = j;
return j;
}
}
pos[i] = n + 1;
return 0;
}
public void Output(int a[][]) {//输出邻接矩阵
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Adjacency adjacency = new Adjacency();
}
}
package course;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.awt.SystemColor;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
/**
* <p>Title: 界面及主要实现</p>
*
* <p>Description: 界面</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Face extends JFrame {
public static int n;
Topological top = new Topological(); //对象
Adjacency ad = new Adjacency();
public static int aa[][] = new int[n + 1][n + 1];
public static String a[]; //保存课名
public static String b[];
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox2 = new JComboBox();
JComboBox jComboBox3 = new JComboBox();
JLabel jLabel4 = new JLabel();
JCheckBox jCheckBox1 = new JCheckBox();
JButton jButton1 = new JButton();
JButton jButton3 = new JButton();
JTextArea jTextArea1 = new JTextArea();
JTextArea jTextArea2 = new JTextArea();
JTextArea jTextArea3 = new JTextArea();
JTextArea jTextArea4 = new JTextArea();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
public Face() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
titledBorder2 = new TitledBorder("课程设定");
titledBorder1 = new TitledBorder("课表显示");
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(525, 636));
setTitle("Frame Title");
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
jLabel1.setForeground(Color.red);
jLabel1.setText("排课表");
jLabel1.setBounds(new Rectangle(220, 14, 73, 28));
jLabel2.setText("添加课程:");
jLabel2.setBounds(new Rectangle(35, 100, 77, 25));
jLabel3.setText("选课的数量:");
jLabel3.setBounds(new Rectangle(35, 65, 90, 25));
jTextField1.setBounds(new Rectangle(148, 66, 148, 22));
jComboBox1.setBounds(new Rectangle(33, 165, 145, 22));
jComboBox2.setBounds(new Rectangle(299, 165, 145, 22));
jLabel4.setText("选择科目,并确定先行级:");
jLabel4.setBounds(new Rectangle(31, 137, 153, 21));
jCheckBox1.setText("先行课");
jCheckBox1.setBounds(new Rectangle(182, 165, 80, 21));
jButton1.setBounds(new Rectangle(79, 200, 69, 24));
jButton1.setText("设定");
jButton1.addActionListener(new Face_jButton1_actionAdapter(this));
jButton3.setBounds(new Rectangle(320, 200, 69, 24));
jButton3.setText("查看");
jButton3.addActionListener(new Face_jButton3_actionAdapter(this));
jTextArea1.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea2.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea3.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea4.setBorder(BorderFactory.createLineBorder(Color.black));
jLabel5.setText("第一学期");
jLabel5.setBounds(new Rectangle(35, 254, 66, 15));
jLabel6.setText("第二学期");
jLabel6.setBounds(new Rectangle(169, 254, 66, 15));
jLabel7.setText("第三学期");
jLabel7.setBounds(new Rectangle(295, 254, 66, 15));
jLabel8.setText("第四学期");
jLabel8.setBounds(new Rectangle(413, 255, 66, 15));
jButton4.setBounds(new Rectangle(168, 595, 73, 23));
jButton4.setText("课表");
jButton4.addActionListener(new Face_jButton4_actionAdapter(this));
jButton5.setBounds(new Rectangle(294, 596, 73, 23));
jButton5.setText("退出");
jButton5.addActionListener(new Face_jButton5_actionAdapter(this));
jButton6.setBounds(new Rectangle(326, 101, 70, 23));
jButton6.setText("添加");
jButton6.addActionListener(new Face_jButton6_actionAdapter(this));
jButton7.setBounds(new Rectangle(326, 62, 70, 23));
jButton7.setText("确定");
jButton7.addActionListener(new Face_jButton7_actionAdapter(this));
jComboBox3.setBounds(new Rectangle(148, 102, 148, 22));
contentPane.setBackground(UIManager.getColor(
"CheckBoxMenuItem.selectionBackground"));
jLabel9.setBackground(Color.gray);
jLabel9.setBorder(titledBorder1);
jLabel9.setBounds(new Rectangle(9, 229, 512, 394));
jLabel10.setBorder(titledBorder2);
jLabel10.setBounds(new Rectangle(8, 42, 508, 193));
jScrollPane1.setBounds(new Rectangle(13, 270, 121, 146));
jScrollPane2.setBounds(new Rectangle(140, 268, 121, 146));
jScrollPane3.setBounds(new Rectangle(268, 268, 121, 146));
jScrollPane4.setBounds(new Rectangle(395, 268, 121, 146));
jScrollPane5.setBounds(new Rectangle(13, 443, 121, 151));
jScrollPane6.setBounds(new Rectangle(141, 443, 121, 151));
jScrollPane7.setBounds(new Rectangle(269, 443, 121, 151));
jScrollPane8.setBounds(new Rectangle(397, 443, 121, 151));
jLabel11.setText("第五学期");
jLabel11.setBounds(new Rectangle(34, 421, 82, 20));
jLabel12.setText("第六学期");
jLabel12.setBounds(new Rectangle(169, 421, 58, 22));
jLabel13.setText("第七学期");
jLabel13.setBounds(new Rectangle(294, 421, 80, 20));
jLabel14.setText("第八学期");
jLabel14.setBounds(new Rectangle(413, 420, 68, 20));
jTextArea5.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea6.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea7.setBorder(BorderFactory.createLineBorder(Color.black));
jTextArea8.setBorder(BorderFactory.createLineBorder(Color.black));
x.getContentPane().setBackground(UIManager.getColor("inactiveCaption"));
x.setForeground(Color.black);
contentPane.add(jLabel1);
contentPane.add(jLabel4);
contentPane.add(jComboBox1);
contentPane.add(jCheckBox1);
contentPane.add(jComboBox2);
contentPane.add(jButton1);
contentPane.add(jButton3);
contentPane.add(jLabel5);
contentPane.add(jLabel6);
contentPane.add(jLabel7);
contentPane.add(jLabel8);
contentPane.add(jLabel2);
contentPane.add(jTextField1);
contentPane.add(jLabel3);
contentPane.add(jButton7);
contentPane.add(jButton6);
contentPane.add(jComboBox3);
contentPane.add(jLabel10);
contentPane.add(jScrollPane1);
contentPane.add(jLabel9);
contentPane.add(jScrollPane2);
contentPane.add(jScrollPane3);
jScrollPane3.getViewport().add(jTextArea3);
contentPane.add(jScrollPane4);
jScrollPane4.getViewport().add(jTextArea4);
contentPane.add(jScrollPane5);
jScrollPane5.getViewport().add(jTextArea5);
contentPane.add(jScrollPane6);
jScrollPane6.getViewport().add(jTextArea6);
contentPane.add(jScrollPane7);
jScrollPane7.getViewport().add(jTextArea7);
contentPane.add(jScrollPane8);
contentPane.add(jLabel11);
contentPane.add(jLabel12);
contentPane.add(jLabel13);
contentPane.add(jLabel14);
contentPane.add(jButton4);
contentPane.add(jButton5);
jScrollPane8.getViewport().add(jTextArea8);
jScrollPane2.getViewport().add(jTextArea2);
jScrollPane1.getViewport().add(jTextArea1);
jComboBox3.addItem("(1)高等数学"); //科目名称可随意添加
jComboBox3.addItem("(2)线性代数");
jComboBox3.addItem("(3)JAVA程序设计");
jComboBox3.addItem("(4)计算机引论");
jComboBox3.addItem("(5)LINUX");
jComboBox3.addItem("(6)数据结构");
jComboBox3.addItem("(7)操作系统");
jComboBox3.addItem("(8)数据库系统");
jComboBox3.addItem("(9)邓小平理论");
jComboBox3.addItem("(10)数据库课程设计");
jComboBox3.addItem("(11)微机原理与接口");
jComboBox3.addItem("(12)大学英语");
jComboBox3.addItem("(13)数值分析");
jComboBox3.addItem("(14)计算机组成原理");
jComboBox3.addItem("(15)体育");
jComboBox3.addItem("(16)中华民族历史与精神");
jComboBox3.addItem("(17)传统文学修养");
jComboBox3.addItem("(18)军事理论");
jComboBox3.addItem("(19)马克思主义哲学");
jComboBox3.addItem("(20)马克思主义政治经济学");
jComboBox3.addItem("(21)思想道德修养");
jComboBox3.addItem("(22)法律基础");
}
//初始化数组
void Initialize(int i) { //初始化数组
a = new String[i];
b = new String[i];
}
//选课数量
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?